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
|
#include <tcl.h>
#include <string.h>
#include <limits.h>
#include <float.h>
#include "container.h"
#include "xalloc.h"
#include "tcl_utils.h"
#include "canvas_box.h"
#include "text_output.h"
#include "element_canvas.h"
#include "container_ruler.h"
static container **container_array; /* array */
static int container_num = 0; /* current element of array */
static int container_size = 0; /* current size of array */
void delete_element(element *e, int job);
void container_update_scrollregion(Tcl_Interp *interp, container *c);
/*
* delete entire container array
*/
void shutdown_container(void)
{
xfree(container_array);
container_num = 0;
container_size = 0;
}
int container_id_to_num(int container_id)
{
int i;
for (i = 0; i < container_num; i++) {
if (container_array[i]->id == container_id) {
return i;
}
}
return -1;
}
/*
* shutdown single container
*/
void delete_container(container *c) {
int c_num;
char cmd[1024];
#ifdef DEBUG
printf("DELETE CONTAINER\n");
#endif
if (-1 == (c_num = container_id_to_num(c->id))) {
/* already deleted */
return;
}
sprintf(cmd, "destroy %s", c->win);
Tcl_Eval(c->interp, cmd);
c->num_rows = 0;
c->num_columns = 0;
/* only move if not the last container in array */
if (c_num < container_num - 1) {
memmove(&container_array[c_num], &container_array[c_num+1],
sizeof(container *));
}
if (container_num > 0)
container_num--;
}
void container_start_shutdown(int container_id)
{
container *c = get_container(container_id);
element *e;
int i, j, cnt;
int num_rows = c->num_rows;
int num_columns = c->num_columns;
int *e_id;
/* need to set num_rows and num_columns as the shutdown func will alter
* these
*/
if (NULL == (e_id = (int *)xmalloc((c->num_rows * c->num_columns) *
sizeof(int))))
return;
cnt = 0;
for (i = 0; i < num_rows; i++) {
for (j = 0; j < num_columns; j++) {
e = c->matrix[i][j];
if (e) {
e_id[cnt++] = e->id;
}
}
}
c->status = 1;
for (i = 0; i < cnt; i++) {
e = get_element(e_id[i]);
if (e) {
e->shutdown_func(e, ALL);
}
}
xfree(e_id);
delete_container(c);
}
/* allocates a unique identifier and window name to container */
int new_container(Tcl_Interp *interp,
char **c_win)
{
static int container_id = 0;
char *win;
win = get_default_string(interp, tk_utils_defs, w("CONTAINER.WIN"));
if (NULL == (*c_win = (char *)xmalloc((strlen(win) + 10) *
sizeof(char))))
return -1;
sprintf(*c_win, "%s%d", win, container_id);
return container_id++;
}
/*
* creates container_array if necessary
* adds new container to container_array
*/
container *create_container(Tcl_Interp *interp,
char *c_win,
int container_id)
{
int incr_num = 10;
int i;
ruler_s *ruler;
tick_s *tick;
if (container_size == 0) {
container_size += incr_num;
if (NULL == (container_array = (container **)xmalloc(container_size *
sizeof(container*)))){
shutdown_container();
return NULL;
}
for (i = container_num; i < container_size; i++) {
if (NULL == (container_array[i] = (container *)xmalloc(sizeof(container)))) {
return NULL;
}
}
}
/* DEBUG - need to check this! */
if (container_num >= container_size) {
container_size += incr_num;
if (NULL == (container_array = (container **)xrealloc(container_array,
(container_size) *
sizeof(container*)))) {
shutdown_container();
return NULL;
}
for (i = container_num; i < container_size; i++) {
if (NULL == (container_array[i] = (container *)xmalloc(sizeof(container)))) {
return NULL;
}
}
}
/* intialise container */
container_array[container_num]->interp = interp;
container_array[container_num]->win = strdup(c_win);
container_array[container_num]->id = container_id;
container_array[container_num]->matrix = NULL;
container_array[container_num]->row = NULL;
container_array[container_num]->column = NULL;
container_array[container_num]->num_rows = 0;
container_array[container_num]->max_rows = 0;
container_array[container_num]->num_columns = 0;
container_array[container_num]->max_columns = 0;
container_array[container_num]->status = 0;
ruler = ruler_struct(interp, tk_utils_defs, "CONTAINER", 0);
tick = tick_struct(interp, tk_utils_defs, "CONTAINER", -1, -1, "");
container_array[container_num]->ruler = ruler;
container_array[container_num]->tick = tick;
return container_array[container_num++];
}
container *get_container(int container_id)
{
int i;
for (i = 0; i < container_num; i++) {
if (container_array[i]->id == container_id)
return container_array[i];
}
return NULL;
}
/*
* given an array of seqs, find a container which contains one of the
* "direction" sequences in the same direction
*/
int find_container(seq_id_dir *seq_ids,
int num_seqs,
int *direction,
char **e_win,
char **c_win)
{
container *c;
element *e;
int i, j, k, l, m;
for (i = 0; i < container_num; i++) {
c = container_array[i];
for (j = 0; j < c->num_rows; j++) {
for (k = 0; k < c->num_columns; k++) {
e = c->matrix[j][k];
if (e) {
for (l = 0; l < num_seqs; l++) {
for (m = 0; m < e->num_seqs; m++) {
#ifdef DEBUG
printf("!!!!!!seq_ids %d %d %d %d %d\n", *direction,
seq_ids[l].seq_id,
seq_ids[l].direction,
e->seqs[m].seq_id,
e->seqs[m].direction);
#endif
if (seq_ids[l].seq_id == e->seqs[m].seq_id) {
*c_win = c->win;
*direction = e->seqs[m].direction;
*e_win = e->win;
return container_array[i]->id;
}
}
}
}
}
}
}
return (-1);
}
int init_row(coord *row)
{
if (NULL == (row->pixel = (CanvasPtr *)xmalloc(sizeof(CanvasPtr))))
return -1;
row->pixel->width = 0;
row->pixel->height = 0;
row->pixel->x = 0;
row->pixel->y = 0;
row->pixel->ax = 0;
row->pixel->ay = 0;
row->pixel->bx = 0;
row->pixel->by = 0;
row->visible.min = INT_MAX;
row->visible.max = INT_MIN;
row->total.min = INT_MAX;
row->total.max = INT_MIN;
row->ruler = NULL;
row->ruler_reg = 0;
createZoom(&row->zoom);
return 0;
}
int init_column(coord *column)
{
if (NULL == (column->pixel = (CanvasPtr *)xmalloc(sizeof(CanvasPtr))))
return -1;
column->pixel->width = 0;
column->pixel->height = 0;
column->pixel->x = 0;
column->pixel->y = 0;
column->pixel->ax = 0;
column->pixel->ay = 0;
column->pixel->bx = 0;
column->pixel->by = 0;
column->visible.min = INT_MAX;
column->visible.max = INT_MIN;
column->total.min = INT_MAX;
column->total.max = INT_MIN;
column->ruler = NULL;
column->ruler_reg = 0;
createZoom(&column->zoom);
return 0;
}
int init_container_matrix(container *c,
int row_num,
int column_num,
int *r_index,
int *c_index)
{
int incr = 10;
int i, j;
c->max_rows += incr;
c->max_columns += incr;
if (NULL == (c->matrix = (element ***)xmalloc(c->max_rows *
sizeof(element **))))
return -1;
for (i = 0; i < c->max_rows; i++) {
if (NULL == (c->matrix[i] = (element **)xmalloc(c->max_columns *
sizeof(element*))))
return -1;
}
for (i = 0; i < c->max_rows; i++) {
for (j = 0; j < c->max_columns; j++) {
c->matrix[i][j] = NULL;
}
}
if (NULL == (c->row = (coord **)xmalloc(c->max_rows * sizeof(coord*))))
return -1;
if (NULL == (c->column = (coord **)xmalloc(c->max_columns * sizeof(coord*))))
return -1;
for (i = 0; i < c->max_rows; i++) {
if (NULL == (c->row[i] = (coord *)malloc(sizeof(coord))))
return -1;
init_row(c->row[i]);
}
for (i = 0; i < c->max_columns; i++) {
if (NULL == (c->column[i] = (coord *)malloc(sizeof(coord))))
return -1;
init_column(c->column[i]);
}
c->num_rows++;
c->num_columns++;
*r_index = 0;
*c_index = 0;
/* row number */
return 0;
}
void init_pixel(Tcl_Interp *interp,
element *e,
CanvasPtr *canvas) /* in, out */
{
/* assume if one isn't defined, none of them are */
if (!e->element_width)
return;
canvas->width = e->element_width(interp, e->win);
canvas->height = e->element_height(interp, e->win);
canvas->x = 0;
canvas->y = 0;
canvas->ax = 0;
canvas->ay = 0;
canvas->bx = 0;
canvas->by = 0;
}
/*
* go through all results in element to accumulate scaling for element
*/
int check_element_scale(element *e)
{
int i;
int scale = 0;
for (i = 0; i < e->num_results; i++) {
#ifdef DEBUG
printf("RESULTS SCALE %s %d\n", e->win, e->results[i]->scale);
#endif
if (e->results[i]->scale & SCALE_X) {
scale |= SCALE_X;
}
if (e->results[i]->scale & SCALE_Y) {
scale |= SCALE_Y;
}
}
return scale;
}
/*
* go through all results in element to check for length ruler
*/
int check_element_len_ruler(element *e)
{
int i;
for (i = 0; i < e->num_results; i++) {
if (e->results[i]->len_ruler) {
return 1;
}
}
return 0;
}
/*
* go through all results in element to check for amplitude ruler
*/
int check_element_amp_ruler(element *e)
{
int i;
for (i = 0; i < e->num_results; i++) {
if (e->results[i]->amp_ruler) {
return 1;
}
}
return 0;
}
int get_element_row(Tcl_Interp *interp,
char *win)
{
char cmd[1024];
sprintf(cmd, "get_element_row %s", win);
Tcl_Eval(interp, cmd);
return (atoi(Tcl_GetStringResult(interp)));
}
int get_element_column(Tcl_Interp *interp,
char *win)
{
char cmd[1024];
sprintf(cmd, "get_element_column %s", win);
Tcl_Eval(interp, cmd);
return (atoi(Tcl_GetStringResult(interp)));
}
int alloc_more_rows(container *c)
{
int incr = 10;
int prev_max = c->max_rows;
int i, j;
#ifdef DEBUG
printf("alloc_more_rows num %d max %d\n", c->num_rows, c->max_rows);
#endif
if (c->num_rows >= c->max_rows) {
c->max_rows += incr;
if (NULL == (c->matrix = (element ***)xrealloc(c->matrix, c->max_rows *
sizeof(element **))))
return -1;
if (NULL == (c->row = (coord **)xrealloc(c->row, c->max_rows * sizeof(coord*))))
return -1;
/* initialiase rows */
for (i = prev_max; i < c->max_rows; i++) {
if (NULL == (c->matrix[i] = (element **)xmalloc(c->max_columns * sizeof(element*))))
return -1;
if (NULL == (c->row[i] = (coord *)xmalloc(sizeof(coord))))
init_row(c->row[i]);
}
/* initialise new elements */
for (i = prev_max; i < c->max_rows; i++) {
for (j = 0; j < c->max_columns; j++) {
c->matrix[i][j] = NULL;
}
}
if (c->max_columns == 0) {
c->max_columns++;
c->num_columns++;
}
}
return 0;
}
/* adds an entire row */
int add_row_to_container(container *c,
int row_index,
int column_index,
int row_num,
int min,
int max)
{
int i, j;
#ifdef DEBUG
printf("add_row_to_container num %d max %d\n", c->num_rows, c->max_rows);
#endif
alloc_more_rows(c);
/*
* need to modify the row_index for all those elements which will be moved
* by the subsequent memmove
*/
for (i = row_index; i < c->num_rows; i++) {
for (j = column_index; j < c->num_columns; j++) {
if (c->matrix[i][j])
c->matrix[i][j]->row_index++;
}
}
/* only move if not the last row in array */
if (row_index < c->num_rows) {
memmove(&c->row[row_index + 1],
&c->row[row_index],
(c->num_rows - row_index) * sizeof(coord*));
memmove(&c->matrix[row_index + 1],
&c->matrix[row_index],
(c->num_rows - row_index) * sizeof(element*));
}
/* allocate new row */
if (NULL == (c->row[row_index] = (coord *)malloc(sizeof(coord))))
return -1;
init_row(c->row[row_index]);
if (NULL == (c->matrix[row_index] = (element **)malloc(c->max_columns *
sizeof(element*))))
return -1;
for (i = 0; i < c->max_columns; i++) {
c->matrix[row_index][i] = NULL;
}
c->num_rows++;
return 0;
}
int alloc_more_columns(container *c)
{
int incr = 3;
int prev_max = c->max_columns;
int i, j;
if (c->num_columns >= c->max_columns) {
c->max_columns += incr;
if (c->max_rows == 0) {
c->max_rows++;
c->num_rows++;
if (NULL == (c->matrix = (element ***)xrealloc(c->matrix, c->max_rows * sizeof(element **))))
return -1;
}
if (NULL == (c->column = (coord **)xrealloc(c->column, c->max_columns * sizeof(coord*))))
return -1;
/* initialise columns */
for (i = prev_max; i < c->max_columns; i++) {
if (NULL == (c->column[i] = (coord *)xmalloc(sizeof(coord))))
return -1;
init_column(c->column[i]);
}
for (i = 0; i < c->max_rows; i++) {
if (NULL == (c->matrix[i] = (element **)xrealloc(c->matrix[i],
c->max_columns * sizeof(element*))))
return -1;
for (j = prev_max; j < c->max_columns; j++) {
c->matrix[i][j] = NULL;
}
}
}
return 0;
}
int add_column_to_container(container *c,
int row_index,
int column_index,
int column_num,
int min,
int max)
{
int i, j;
#ifdef DEBUG
printf("add_column_to_container\n");
#endif
alloc_more_columns(c);
/*
* need to modify the row_index for all those elements which will be moved
* by the subsequent memmove
*/
for (i = row_index; i < c->num_rows; i++) {
for (j = column_index; j < c->num_columns; j++) {
c->matrix[i][j]->column_index++;
}
}
/* only move if not the last column in array */
if (column_index < c->num_columns) {
memmove(&c->column[column_index + 1],
&c->column[column_index],
(c->num_columns - column_index) * sizeof(coord*));
for (i = 0; i < c->num_rows; i++) {
memmove(&c->matrix[i][column_index + 1],
&c->matrix[i][column_index],
(c->num_columns - column_index) * sizeof(element));
}
}
/* allocate new column */
if (NULL == (c->column[column_index] = (coord *)malloc(sizeof(coord))))
return -1;
init_column(c->column[column_index]);
for (i = 0; i < c->num_rows; i++) {
#ifdef REMOVE
if (NULL == (c->matrix[i][column_index] = (element *)malloc(sizeof(element))))
return -1;
#endif
c->matrix[i][column_index] = NULL;
}
c->num_columns++;
return 0;
}
/* removes entire row */
void delete_row_from_container(container *c,
int row_index,
int column_index)
{
int i, j;
element *e;
#ifdef DEBUG
printf("delete row %d %d\n", row_index, c->num_rows);
#endif
/*
* need to modify the row_index for all those elements which will be moved
* by the subsequent memmove
*/
for (i = row_index; i < c->num_rows; i++) {
for (j = column_index; j < c->num_columns; j++) {
e = c->matrix[i][j];
if (e) {
e->row_index--;
}
}
}
xfree(c->row[row_index]->pixel);
freeZoom(&c->row[row_index]->zoom);
xfree(c->row[row_index]);
/* only move if not the last row in array */
if (row_index < c->num_rows - 1) {
memmove(&c->row[row_index],
&c->row[row_index + 1],
(c->num_rows - row_index - 1) * sizeof(coord *));
}
for (i = row_index; i < c->num_rows-1; i++) {
for (j = 0; j < c->num_columns; j++) {
memmove(&c->matrix[i][j],
&c->matrix[i + 1][j],
sizeof(element *));
}
}
for (i = 0; i < c->num_columns; i++) {
c->matrix[c->num_rows-1][i] = NULL;
}
c->num_rows--;
}
void delete_column_from_container(container *c,
int row_index,
int column_index)
{
int i, j;
element *e;
int cnt = 0;
#ifdef DEBUG
printf("delete column %d %d\n", column_index, c->num_columns);
#endif
if (row_index < 0) {
c->num_columns--;
return;
}
/*
* need to modify the column_index for all those elements which will be moved
* by the subsequent memmove
*/
for (i = 0; i < c->num_rows; i++) {
for (j = column_index; j < c->num_columns; j++) {
e = c->matrix[i][j];
if (e) {
e->column_index--;
cnt++;
}
}
}
xfree(c->column[column_index]->pixel);
freeZoom(&c->column[column_index]->zoom);
xfree(c->column[column_index]);
#ifdef DEBUG
printf("NUM COLUMNS TO MOVE %d\n", cnt);
#endif
/* only move if not the last row in array */
if (column_index < c->num_columns - 1) {
memmove(&c->column[column_index],
&c->column[column_index + 1],
(c->num_columns - column_index - 1) * sizeof(coord *));
for (i = 0; i < c->num_rows; i++) {
memmove(&c->matrix[i][column_index],
&c->matrix[i][column_index + 1],
(cnt) * sizeof(element *));
}
}
for (i = 0; i < c->num_rows; i++) {
c->matrix[i][c->num_columns] = NULL;
}
c->num_columns--;
}
void update_row(element *e)
{
container *c = e->c;
if (e->row_index < 0)
return;
if (e->orientation & VERTICAL) {
c->row[e->row_index]->visible.min = e->world->visible->x1;
c->row[e->row_index]->visible.max = e->world->visible->x2;
}
set_pixel_coords(c->column[e->column_index]->visible.min,
c->row[e->row_index]->visible.min,
c->column[e->column_index]->visible.max,
c->row[e->row_index]->visible.max,
c->row[e->row_index]->pixel);
container_update_scrollregion(e->c->interp, e->c);
}
void update_column(element *e)
{
container *c = e->c;
if (e->column_index < 0)
return;
if (e->orientation & HORIZONTAL) {
if (e->world->visible->x1 > c->column[e->column_index]->visible.min)
c->column[e->column_index]->visible.min = e->world->visible->x1;
if (e->world->visible->x2 < c->column[e->column_index]->visible.max)
c->column[e->column_index]->visible.max = e->world->visible->x2;
}
set_pixel_coords(c->column[e->column_index]->visible.min,
c->row[e->row_index]->visible.min,
c->column[e->column_index]->visible.max,
c->row[e->row_index]->visible.max,
c->column[e->column_index]->pixel);
container_update_scrollregion(e->c->interp, e->c);
}
void delete_element_from_container(element *e)
{
int i, j;
container *c = e->c;
int row_delete = 1;
int column_delete = 1;
char cmd[1024];
int row_num, column_num;
int num = 0;
#ifdef DEBUG
printf("delete_element_from_container %s row_index %d column_index %d num cols %d num rows %d type %d\n",
e->win, e->row_index, e->column_index, c->num_columns, c->num_rows, e->type);
print_elements_in_container(c);
#endif
if (c->num_rows == 1 && c->num_columns == 1) {
delete_container(c);
return;
}
/* if ((e->type == RULER_AMP) || (e->type == RULER_LEN)) { */
if (e->type == RULER_LEN) {
row_delete = 0;
column_delete = 0;
} else if (e->type == RULER_AMP) {
Tcl_VarEval(c->interp, "is_empty_column ", e->win, NULL);
if (!atoi(Tcl_GetStringResult(c->interp))) {
column_delete = 0;
}
Tcl_VarEval(c->interp, "is_empty_row ", e->win, NULL);
if (!atoi(Tcl_GetStringResult(c->interp))) {
row_delete = 0;
}
#if 0
for (i = 0; i < c->num_columns; i++) {
if (i != e->column_index && c->matrix[e->row_index][i]) {
row_delete = 0;
}
}
for (i = 0; i < c->num_rows; i++) {
if (i != e->row_index && c->matrix[i][e->column_index]) {
column_delete = 0;
}
}
#endif
} else {
/* check if need to delete entire row */
for (i = 0; i < c->num_columns; i++) {
if (i != e->column_index && c->matrix[e->row_index][i] != NULL
&& (c->matrix[e->row_index][i]->type != RULER_AMP) && (c->matrix[e->row_index][i]->type != RULER_LEN)) {
row_delete = 0;
break;
}
}
/* check if need to delete entire column */
for (i = 0; i < c->num_rows; i++) {
if (i != e->row_index && c->matrix[i][e->column_index] != NULL
&& (c->matrix[i][e->column_index]->type != RULER_AMP) && (c->matrix[i][e->column_index]->type != RULER_LEN)) {
column_delete = 0;
break;
}
}
}
#ifdef DEBUG
printf("row_delete %d column_delete %d\n", row_delete, column_delete);
#endif
if (row_delete) {
/* delete all windows in row */
row_num = get_element_row(c->interp, e->win);
sprintf(cmd, "tcl_delete_row %s %d", c->win, row_num);
if (TCL_OK != (Tcl_Eval(c->interp, cmd)))
printf("tcl_delete_row %s\n", Tcl_GetStringResult(c->interp));
/* length ruler */
if (c->row[e->row_index]->ruler) {
c->row[e->row_index]->ruler->shutdown_func(c->row[e->row_index]->ruler, ALL);
c->row[e->row_index]->ruler = NULL;
}
/* amplitude ruler */
#ifdef DEBUG
printf("Delete ruler %s %d\n", e->win, e->ruler_id);
#endif
if (e->ruler_id > -1) {
delete_element(get_element(e->ruler_id), ALL);
e->ruler_id = -1;
}
delete_row_from_container(e->c, e->row_index, e->column_index);
/* update_row(e); */
}
if (column_delete) {
/* delete all windows in column */
column_num = get_element_column(c->interp, e->win);
sprintf(cmd, "tcl_delete_column %s %d", c->win, column_num);
if (TCL_OK != (Tcl_Eval(c->interp, cmd)))
printf("tcl_delete_column %s\n", Tcl_GetStringResult(c->interp));
if (c->column[e->column_index]->ruler && (e != c->column[e->column_index]->ruler)) {
sprintf(cmd, "delete_sb_h %s %d", c->win, column_num);
Tcl_Eval(c->interp, cmd);
c->column[e->column_index]->ruler->shutdown_func(c->column[e->column_index]->ruler, ALL);
c->column[e->column_index]->ruler = NULL;
}
/* amplitude ruler */
if (e->ruler_id > -1) {
#if 0
sprintf(cmd, "delete_sb_h %s %d", c->win, c->column[e->column_index]->num);
Tcl_Eval(c->interp, cmd);
#endif
delete_element(get_element(e->ruler_id), ALL);
e->ruler_id = -1;
}
delete_column_from_container(e->c, e->row_index, e->column_index);
/* update_column(e); */
}
if (!row_delete && !column_delete) {
c->matrix[e->row_index][e->column_index] = NULL;
Tcl_VarEval(c->interp, "tcl_delete_element ", e->win, NULL);
}
if (e->type == RULER_LEN) {
if (e->orientation == HORIZONTAL)
e->c->column[e->column_index]->ruler = NULL;
else
e->c->row[e->row_index]->ruler = NULL;
}
/* if only RULER_LEN elements are left, then delete container */
for (i = 0; i < c->num_rows; i++) {
for (j = 0; j < c->num_columns; j++) {
if (c->matrix[i][j]) {
if (c->matrix[i][j]->type != RULER_LEN) {
num++;
}
}
}
}
if (num == 0) {
/* need to delete ruler */
for (i = 0; i < c->num_rows; i++) {
for (j = 0; j < c->num_columns; j++) {
if (c->matrix[i][j]) {
e->shutdown_func(c->matrix[i][j], ALL);
}
}
}
delete_container(c);
}
}
int find_row_index(container *c,
int row_num,
int *new_row)
{
int i, j;
element *e;
for (i = 0; i < c->num_rows; i++) {
for (j = 0; j < c->num_columns; j++) {
if (e = c->matrix[i][j]) {
if (row_num == get_element_row(c->interp, e->win)) {
*new_row = 0;
return e->row_index;
}
}
}
}
*new_row = 1;
return c->num_rows;
}
int find_column_index(container *c,
int column_num,
int *new_column)
{
int i, j;
element *e;
for (i = 0; i < c->num_rows; i++) {
for (j = 0; j < c->num_columns; j++) {
if (e = c->matrix[i][j]) {
if (column_num == get_element_column(c->interp, e->win)) {
*new_column = 0;
return e->column_index;
}
}
}
}
*new_column = 1;
return c->num_columns;
}
void print_elements_in_container(container *c)
{
int row, column;
for (row = 0; row < c->num_rows; row++) {
for (column = 0; column < c->num_columns; column++) {
printf("%p %d %d\n", c->matrix[row], row, column);
if (c->matrix[row][column])
print_element(c->matrix[row][column]);
}
}
}
void push_row_zoom(StackPtr **zoom, mm visible)
{
d_box v;
v.x1 = 0;
v.y1 = visible.min;
v.x2 = 0;
v.y2 = visible.max;
pushZoom(zoom, &v);
}
void push_column_zoom(StackPtr **zoom, mm visible)
{
d_box v;
v.x1 = visible.min;
v.y1 = 0;
v.x2 = visible.max;
v.y2 = 0;
pushZoom(zoom, &v);
}
void container_update_scrollregion(Tcl_Interp *interp,
container *c)
{
int i, j;
element *e;
for (i = 0; i < c->num_rows; i++) {
for (j = 0; j < c->num_columns; j++) {
e = c->matrix[i][j];
if (e){
/*
if (e->scale_func) {
bbox = scale_box(e);
printf("BBOX %s %f %f %f %f\n", e->win, bbox.x1, bbox.x2,
bbox.y1, bbox.y2);
e->scale_func(interp, e, -1, &bbox, e->pixel);
}
*/
if (e->scrollregion_func)
e->scrollregion_func(interp, e, e->world->total,
c->column[e->column_index]->pixel,
c->row[e->row_index]->pixel);
}
}
}
}
int add_element_to_container(Tcl_Interp *interp,
int container_id,
char *c_win,
element *e,
int min_h,
int max_h,
int min_v,
int max_v)
{
int row_num, column_num;
container *c;
int new_row = 0;
int new_column = 0;
int update_scrollregion = 0;
int row_index, column_index;
int draw_row_ruler = 0;
int draw_column_ruler = 0;
if (NULL == (c = get_container(container_id))) {
c = create_container(interp, c_win, container_id);
}
/* get row and column numbers from tcl grid */
row_num = get_element_row(interp, e->win);
column_num = get_element_column(interp, e->win);
#ifdef DEBUG
printf("ROW NUM %d COL %d\n", row_num, column_num);
#endif
row_index = find_row_index(c, row_num, &new_row);
column_index = find_column_index(c, column_num, &new_column);
#ifdef DEBUG
printf("INDEX %d %d\n", row_index, column_index);
printf("NEW_ROW %d NEW_COLUMN %d\n", new_row, new_column);
#endif
/* if element already exists, delete it */
if (row_index > 0 && column_index > 0 && c->matrix[row_index][column_index]) {
delete_element(c->matrix[row_index][column_index], ALL);
}
e->c = c;
if (e->orientation & HORIZONTAL && check_element_len_ruler(e))
draw_column_ruler = 1;
if (e->orientation & VERTICAL && check_element_len_ruler(e))
draw_row_ruler = 1;
if (c->num_rows == 0 && c->num_columns == 0) {
init_container_matrix(c, row_num, column_num, &row_index, &column_index);
new_row = 1;
new_column = 1;
} else {
if (new_row) {
add_row_to_container(c, row_index, column_index, row_num, min_v,
max_v);
}
if (new_column) {
add_column_to_container(c, row_index, column_index, column_num,
min_h, max_h);
}
}
#ifdef DEBUG
printf("INDEX %d %d\n", row_index, column_index);
#endif
c->matrix[row_index][column_index] = e;
e->row_index = row_index;
e->column_index = column_index;
#ifdef DEBUG
printf("add_element_to_container %d %d\n", row_index, column_index);
print_elements_in_container(c);
printf("min_h %d max_h %d min %f max %f\n", min_h, max_h,
c->column[column_index]->total.min, c->column[column_index]->total.max);
#endif
if (min_h < c->column[column_index]->total.min) {
c->column[column_index]->total.min = min_h;
update_scrollregion = 1;
}
if (max_h > c->column[column_index]->total.max) {
c->column[column_index]->total.max = max_h;
update_scrollregion = 1;
}
if (min_v < c->row[row_index]->total.min) {
c->row[row_index]->total.min = min_v;
update_scrollregion = 1;
}
if (max_v > c->row[row_index]->total.max) {
c->row[row_index]->total.max = max_v;
update_scrollregion = 1;
}
/* initialise visible */
if (c->row[row_index]->visible.min == INT_MAX)
c->row[row_index]->visible.min = c->row[row_index]->total.min;
if (c->row[row_index]->visible.max == INT_MIN)
c->row[row_index]->visible.max = c->row[row_index]->total.max;
if (c->column[column_index]->visible.min == INT_MAX)
c->column[column_index]->visible.min = c->column[column_index]->total.min;
if (c->column[column_index]->visible.max == INT_MIN)
c->column[column_index]->visible.max = c->column[column_index]->total.max;
if (new_row) {
init_pixel(interp, e, c->row[row_index]->pixel);
set_pixel_coords(c->column[column_index]->visible.min,
c->row[row_index]->visible.min,
c->column[column_index]->visible.max,
c->row[row_index]->visible.max,
c->row[row_index]->pixel);
push_row_zoom(&c->row[row_index]->zoom, c->row[row_index]->visible);
if (draw_row_ruler && !c->row[row_index]->ruler)
add_length_ruler(c->interp, c, row_index, column_index, row_num, column_num, VERTICAL);
}
if (new_column) {
init_pixel(interp, e, c->column[column_index]->pixel);
set_pixel_coords(c->column[column_index]->visible.min, 0,
c->column[column_index]->visible.max, 0,
c->column[column_index]->pixel);
push_column_zoom(&c->column[column_index]->zoom, c->column[column_index]->visible);
if (draw_column_ruler && !c->column[column_index]->ruler)
add_length_ruler(c->interp, c, row_index, column_index, row_num, column_num, HORIZONTAL);
}
/* don't do this first time round */
if (update_scrollregion && !(new_row && new_column)) {
container_update_scrollregion(interp, c);
}
if (check_element_amp_ruler(e) && !e->ruler && e->orientation & HORIZONTAL)
add_element_ruler(interp, c, e, VERTICAL);
if (check_element_amp_ruler(e) && !e->ruler && e->orientation & VERTICAL)
add_element_ruler(interp, c, e, HORIZONTAL);
if (check_element_len_ruler(e) && !(new_row && new_column)) {
if (e->orientation & HORIZONTAL)
update_length_ruler(interp, c, c->column[column_index]);
if (e->orientation & VERTICAL)
update_length_ruler(interp, c, c->row[row_index]);
}
return 0;
}
int new_element(Tcl_Interp *interp,
char **e_win)
{
static int element_id = 0;
char *win;
win = get_default_string(interp, tk_utils_defs, w("ELEMENT.WIN"));
if (NULL == (*e_win = (char *)xmalloc((strlen(win)+10) * sizeof(char))))
return -1;
sprintf(*e_win, "%s%d", win, element_id);
return element_id++;
}
element *create_element(Tcl_Interp *interp,
int container_id,
int element_id,
char *e_win,
int orientation,
int crosshair)
{
element *e;
#ifdef DEBUG
printf("create_element %d %s\n", element_id, e_win);
#endif
if (NULL == (e = (element *)xmalloc(sizeof(element))))
return NULL;
e->id = element_id;
e->win = strdup(e_win);
e->num_seqs = 0;
e->max_seqs = 0;
e->seqs = NULL;
e->num_results = 0;
e->max_results = 0;
e->results = NULL;
e->status = 0;
e->container_id = container_id;
e->c = NULL;
e->crosshair = crosshair;
if (NULL == (e->pixel = (CanvasPtr *)xmalloc(sizeof(CanvasPtr))))
return NULL;
if (NULL == (e->world= (WorldPtr *)xmalloc(sizeof(WorldPtr))))
return NULL;
if (NULL == (e->world->visible = (d_box *)xmalloc(sizeof(d_box))))
return NULL;
if (NULL == (e->world->total = (d_box *)xmalloc(sizeof(d_box))))
return NULL;
createZoom(&e->zoom);
e->world->total->x1 = DBL_MAX;
e->world->total->x2 = -DBL_MAX;
e->world->total->y1 = DBL_MAX;
e->world->total->y2 = -DBL_MAX;
e->world->visible->x1 = DBL_MAX;
e->world->visible->x2 = -DBL_MAX;
e->world->visible->y1 = DBL_MAX;
e->world->visible->y2 = -DBL_MAX;
e->type = -1;
e->orientation = orientation;
e->min_y = DBL_MAX;
e->max_y = -DBL_MAX;
e->min_x = INT_MAX;
e->max_x = INT_MIN;
e->cursor = NULL;
e->cursor_array = NULL;
e->cursor_visible = 0;
e->ruler = NULL;
e->ruler_id = -1;
e->parent = -1;
e->num_children_left = 0;
e->num_children_right = 0;
e->children_id = -1;
e->children_position = 0;
e->seq_e_id = -1;
e->replot_func = NULL;
return e;
}
void delete_element(element *e,
int job)
{
int i;
if (!e) {
return;
}
#ifdef DEBUG
printf("***** delete_element %s\n", e->win);
#endif
delete_element_from_container(e);
if (e->ruler) {
xfree(e->ruler->window);
xfree(e->ruler);
}
xfree(e->pixel);
xfree(e->world->visible);
xfree(e->world->total);
xfree(e->world);
freeZoom(&e->zoom);
if (job == ALL) {
for (i = 0; i < e->num_results; i++) {
if (e->results[i]->n_configure > 0) {
xfree(e->results[i]->configure[0]);
if (e->results[i]->n_configure == 2)
xfree(e->results[i]->configure[1]);
xfree(e->results[i]->configure);
}
if (e->results[i]->colour)
free(e->results[i]->colour);
xfree(e->results[i]);
}
}
xfree(e->results);
xfree(e->cursor);
xfree(e->cursor_array);
xfree(e->seqs);
free(e->win);
xfree(e);
}
void print_element(element *e) {
printf("PRINT ELEMENT\n");
printf("win %s ", e->win);
printf("element_id %d ", e->id);
printf("container_id %d ", e->container_id);
printf("row_index %d ", e->row_index);
printf("column_index %d ", e->column_index);
printf("type %d ", e->type);
printf("orientation %d\n", e->orientation);
printf("\n\n");
}
element *get_element(int element_id)
{
int i, r, c;
for (i = 0; i < container_num; i++) {
#ifdef DEBUG
printf("&&&&&&&&&&&&&&&&& get_element r= %d c= %d\n",
container_array[i]->num_rows, container_array[i]->num_columns);
#endif
for (r = 0; r < container_array[i]->num_rows; r++) {
for (c = 0; c < container_array[i]->num_columns; c++) {
if (container_array[i]->matrix[r][c]) {
#ifdef DEBUG
printf("matrix[%d][%d]=%s %d\n", r, c, container_array[i]->matrix[r][c]->win,
container_array[i]->matrix[r][c]->id);
#endif
if (container_array[i]->matrix[r][c]->id == element_id) {
return (container_array[i]->matrix[r][c]);
}
}
}
}
}
return NULL;
}
char *element_window(char *c_win,
char *e_win)
{
char *window;
if (NULL == (window = (char *)xmalloc(strlen(c_win)+strlen(e_win) *
sizeof(char))))
return NULL;
sprintf(window, "%s%s", c_win, e_win);
return (window);
}
/*
* find if seq_id of orientation exists and return container_id & element_id
*/
int find_seq_id(int seq_id,
int orientation,
int *container_id,
int *element_id)
{
int i, j, r, c;
for (i = 0; i < container_num; i++) {
for (r = 0; r < container_array[i]->num_rows; r++) {
for (c = 0; c < container_array[i]->num_columns; c++) {
for (j = 0; j < container_array[i]->matrix[r][c]->num_seqs; j++) {
if ((seq_id == container_array[i]->matrix[r][c]->seqs[j].seq_id) && (orientation == container_array[i]->matrix[r][c]->seqs[j].direction)) {
*container_id = container_array[i]->matrix[r][c]->container_id;
*element_id = container_array[i]->matrix[r][c]->id;
return 0;
}
}
}
}
}
return -1;
}
int set_element_type(element *e,
int type)
{
e->type = type;
if (e->type == SEQ_EDITOR) {
e->scroll_x_func = NULL;
e->scroll_y_func = NULL;
e->scale_func = NULL;
e->scrollregion_func = NULL;
e->draw_crosshair_func = NULL;
e->delete_crosshair_func = NULL;
e->element_width = NULL;
e->element_height = NULL;
e->element_x = NULL;
e->element_y = NULL;
} else if (e->type == CANVAS) {
e->scroll_x_func = canvas_scroll_x;
e->scroll_y_func = canvas_scroll_y;
e->scale_func = canvas_scale;
e->scrollregion_func = canvas_scrollregion;
e->draw_crosshair_func = draw_canvas_crosshair;
e->delete_crosshair_func = delete_canvas_crosshair;
e->element_width = canvas_width;
e->element_height = canvas_height;
e->element_x = canvas_x;
e->element_y = canvas_y;
} else if (e->type == RULER_AMP) {
e->scroll_x_func = canvas_scroll_x;
e->scroll_y_func = canvas_scroll_y;
e->scale_func = canvas_scale;
e->scrollregion_func = canvas_scrollregion;
e->draw_crosshair_func = draw_canvas_crosshair;
e->delete_crosshair_func = delete_canvas_crosshair;
e->element_width = canvas_width;
e->element_height = canvas_height;
e->element_x = canvas_x;
e->element_y = canvas_y;
} else if (e->type == RULER_LEN){
e->scroll_x_func = canvas_scroll_x;
e->scroll_y_func = canvas_scroll_y;
e->scale_func = canvas_scale;
e->scrollregion_func = canvas_scrollregion;
e->draw_crosshair_func = draw_canvas_crosshair;
e->delete_crosshair_func = delete_canvas_crosshair;
e->element_width = canvas_width;
e->element_height = canvas_height;
e->element_x = canvas_x;
e->element_y = canvas_y;
} else {
verror(ERR_WARN, "set_element_type", "Invalid element type");
return -1;
}
return 0;
}
int add_seq_id_to_element(element *e,
int seq_id,
int orientation)
{
int i;
int incr = 10;
#ifdef DEBUG
printf("add_seq_id_to_element %d %d\n", seq_id, orientation);
#endif
/* if no seq_id exists, need to add it */
for (i = 0; i < e->num_seqs; i++) {
if ((e->seqs[i].seq_id == seq_id) && (e->seqs[i].direction & orientation)) {
return 0;
}
}
e->num_seqs++;
if (e->num_seqs > e->max_seqs) {
e->max_seqs += incr;
if (NULL == (e->seqs = (seq_id_dir *)realloc(e->seqs,
e->max_seqs *
sizeof(seq_id_dir))))
return -1;
}
e->seqs[e->num_seqs-1].seq_id = seq_id;
e->seqs[e->num_seqs-1].direction = orientation;
return 0;
}
int add_result_to_element(element *e,
plot_data *result,
double min_x,
double min_y,
double max_x,
double max_y,
int orientation,
int element_type)
{
int incr = 10;
double m, c;
if (-1 == set_element_type(e, element_type))
return -1;
e->num_results++;
if (e->num_results > e->max_results) {
e->max_results += incr;
if (NULL == (e->results = (plot_data **)realloc(e->results,
e->max_results *
sizeof(plot_data *))))
return -1;
}
e->results[e->num_results-1] = result;
e->orientation |= orientation;
if (e->num_results > 1) {
m = (e->max_y - e->min_y) / (max_y - min_y);
c = e->max_y - (m * max_y);
} else {
m = 1.0;
c = 0.0;
}
/*
result->sf_c = (m * result->sf_c) + c;
result->sf_m *= m;
*/
result->sf_c = c;
result->sf_m = m;
#ifdef DEBUG
printf("min_y %f %f max_y %f %f m %f c %f sf_c %f sf_m %f\n",
min_y, e->min_y, max_y, e->max_y, m, c, result->sf_c, result->sf_m);
#endif
min_y = result->sf_m * min_y + result->sf_c;
max_y = result->sf_m * max_y + result->sf_c;
#ifdef DEBUG
printf("after %f %f\n", min_y, max_y);
printf("y1 %f y2 %f\n", e->world->total->y1, e->world->total->y2);
#endif
if (min_y < e->min_y)
e->min_y = min_y;
if (max_y > e->max_y)
e->max_y = max_y;
if (min_x < e->world->total->x1)
e->world->total->x1 = min_x;
if (max_x > e->world->total->x2)
e->world->total->x2 = max_x;
if (min_y < e->world->total->y1)
e->world->total->y1 = min_y;
if (max_y > e->world->total->y2)
e->world->total->y2 = max_y;
return 0;
}
void remove_result_from_element(element *e,
int result_id)
{
int e_num = -1;
int i;
for (i = 0; i < e->num_results; i++) {
if (result_id == e->results[i]->result_id) {
e_num = i;
break;
}
}
if (e_num == -1) {
/* Error */
return;
}
if (e_num < e->num_results-1) {
memmove(&e->results[e_num], &e->results[e_num+1],
(e->num_results - e_num - 1) * sizeof(plot_data *));
}
e->num_results--;
if (e->num_results == 0) {
#if 0
if (e->ruler_id != -1) {
/* delete amplitude ruler */
/* e->shutdown_func(get_element(e->ruler_id), ALL); */
delete_element(get_element(e->ruler_id), ALL);
e->ruler_id = -1;
}
#endif
e->shutdown_func(e, WIN_ONLY);
}
}
/*
* convert between element (pixel) coords and world (base) coords
* element = world * m + c
* world = (element - c) / m
*/
void pixel_to_world(CanvasPtr *pixel,
int px, int py,
double *wx, double *wy)
{
*wx = (px - pixel->bx) / pixel->ax;
*wy = (py - pixel->by) / pixel->ay;
#ifdef DEBUG
printf("CanvasToWorld wx %f wy %f px %d py %d\n", *wx, *wy, px, py);
#endif
}
/*
* convert between world (base) coords and element (pixel) coords
* pixel = world * m + c
*/
void world_to_pixel(CanvasPtr *pixel,
double wx, double wy,
int *px, int *py)
{
*px = (int)ROUND((wx * pixel->ax) + pixel->bx);
*py = (int)ROUND((wy * pixel->ay) + pixel->by);
/*
printf("WorldToCanvas wx %f px %d ax %f bx %f\n",
wx, *px, pixel->ax, pixel->bx);
*/
}
void set_pixel_coords(double x1,
double y1,
double x2,
double y2,
CanvasPtr *pixel) /* out */
{
if (x2 - x1 == 0) {
pixel->ax = 1;
} else {
pixel->ax = pixel->width / (x2-x1);
}
if (y2 - y1 == 0) {
pixel->ay = 1;
} else {
pixel->ay = pixel->height / (y2-y1);
}
pixel->bx = pixel->x - (pixel->ax * x1);
pixel->by = pixel->y - (pixel->ay * y1);
#ifdef DEBUG
printf("********************SET PIXEL COORDS \n");
printf("x1 %f x2 %f y1 %f y2 %f \n", x1, x2, y1, y2);
printf("x %d ax %f ay %f bx %f by %f\n", pixel->x, pixel->ax,
pixel->ay, pixel->bx, pixel->by);
#endif
}
void container_scroll_x (Tcl_Interp *interp,
int container_id,
int column_num,
char *command)
{
container *c;
element *e;
int i;
int column_index;
double dummy;
int new_column;
c = get_container(container_id);
if (!c)
return;
column_index = find_column_index(c, column_num, &new_column);
for (i = 0; i < c->num_rows; i++) {
if (e = c->matrix[i][column_index])
if (e->scroll_x_func)
e->scroll_x_func(interp, e, command);
}
if (e = c->matrix[0][column_index]) {
c->column[e->column_index]->pixel->x = e->element_x(interp, e->win, 0.0);
pixel_to_world(c->column[e->column_index]->pixel,
c->column[e->column_index]->pixel->x, 0,
&c->column[e->column_index]->visible.min, &dummy);
pixel_to_world(c->column[e->column_index]->pixel,
c->column[e->column_index]->pixel->x +
c->column[e->column_index]->pixel->width, 0,
&c->column[e->column_index]->visible.max, &dummy);
set_pixel_coords(c->column[e->column_index]->visible.min, 0,
c->column[e->column_index]->visible.max, 0,
c->column[e->column_index]->pixel);
}
}
void container_scroll_y (Tcl_Interp *interp,
int container_id,
int row_num,
char *command)
{
container *c;
element *e;
int i;
int row_index;
double dummy;
int new_row;
#ifdef DEBUG
printf("container_scroll_y\n");
#endif
c = get_container(container_id);
if (!c)
return;
row_index = find_row_index(c, row_num, &new_row);
for (i = 0; i < c->num_columns; i++) {
if (e = c->matrix[row_index][i])
if (e->scroll_y_func)
e->scroll_y_func(interp, e, command);
}
#if 0
/* kfs 6/1/03 don't know why this is here! */
for (i = 0; i < c->num_rows; i++) {
if (e = c->matrix[i][0]) {
c->row[i]->pixel->y = e->element_y(interp, e->win, 0.0);
pixel_to_world(c->row[i]->pixel,
0, c->row[i]->pixel->y,
&dummy, &c->row[i]->visible.min);
pixel_to_world(c->row[i]->pixel,
0, c->row[i]->pixel->y +
c->row[i]->pixel->height,
&dummy, &c->row[i]->visible.max);
set_pixel_coords(0, c->row[i]->visible.min,
0, c->row[i]->visible.max,
c->row[i]->pixel);
}
}
#endif
e = c->matrix[row_index][0];
c->row[e->row_index]->pixel->y = e->element_y(interp, e->win, 0.0);
pixel_to_world(c->row[e->row_index]->pixel,
0, c->row[e->row_index]->pixel->y,
&dummy, &c->row[e->row_index]->visible.min);
pixel_to_world(c->row[e->row_index]->pixel,
0, c->row[e->row_index]->pixel->y +
c->row[e->row_index]->pixel->height,
&dummy, &c->row[e->row_index]->visible.max);
set_pixel_coords(0, c->row[e->row_index]->visible.min,
0, c->row[e->row_index]->visible.max,
c->row[e->row_index]->pixel);
}
/*
* convert a zoom amount (from button) into a bounding box
*/
void container_convert_zoom(element *e,
float amount,
box *bbox)
{
double length, dist;
double wx1, wx2, wy1, wy2;
length = e->world->visible->x2 - e->world->visible->x1 + 1;
dist = length * amount;
wx1 = (int)(e->world->visible->x1 + dist);
wx2 = (int)(e->world->visible->x2 - dist);
length = e->world->visible->y2 - e->world->visible->y1 + 1;
dist = length * amount;
wy1 = e->world->visible->y1 + dist;
wy2 = e->world->visible->y2 - dist;
world_to_pixel(e->pixel, wx1, wy1, &bbox->x1, &bbox->y1);
world_to_pixel(e->pixel, wx2, wy2, &bbox->x2, &bbox->y2);
}
void element_zoom(Tcl_Interp *interp,
element *e,
float amount,
int x1,
int y1,
int x2,
int y2)
{
d_box bbox;
box zoom;
double w_x1, w_y1, w_x2, w_y2;
container *c = e->c;
if (!e->scale_func)
return;
if (amount != -1) {
container_convert_zoom(e, amount, &zoom);
} else {
zoom.x1 = x1;
zoom.y1 = y1;
zoom.x2 = x2;
zoom.y2 = y2;
}
#ifdef DEBUG
printf("ELEMENT ZOOM %d %d %d %d\n", zoom.x1, zoom.x2, zoom.y1, zoom.y2);
#endif
if (e->world->visible->x1 == DBL_MAX || e->world->visible->x2 == -DBL_MAX
|| e->world->visible->y1 == DBL_MAX || e->world->visible->y2 == -DBL_MAX) {
return;
}
w_x1 = e->world->visible->x1;
w_y1 = e->world->visible->y1;
w_x2 = e->world->visible->x2;
w_y2 = e->world->visible->y2;
#ifdef DEBUG
printf("ZOOM before e %f %f c %f %f\n", e->world->visible->x1,
e->world->visible->x2, c->column[e->column_index]->visible.min,
c->column[e->column_index]->visible.max);
#endif
pixel_to_world(e->pixel, zoom.x1, zoom.y1,
&e->world->visible->x1,
&e->world->visible->y1);
pixel_to_world(e->pixel, zoom.x2, zoom.y2,
&e->world->visible->x2,
&e->world->visible->y2);
#ifdef DEBUG
printf("ZOOM after e %f %f c %f %f\n", e->world->visible->x1,
e->world->visible->x2, c->column[e->column_index]->visible.min,
c->column[e->column_index]->visible.max);
#endif
bbox.x1 = (double)zoom.x1;
bbox.y1 = (double)zoom.y1;
bbox.x2 = (double)zoom.x2;
bbox.y2 = (double)zoom.y2;
/*
* also if drawn a zooming box, only want to zoom in y that window
*/
if (amount == -1) {
#ifdef FIXME
win_num = get_consistency_win_num(c, result_id);
if (i != win_num) {
c->win_list[i]->world->visible->y1 = w_y1;
c->win_list[i]->world->visible->y2 = w_y2;
bbox.y1 = 0;
bbox.y2 = 0;
}
#endif
}
set_pixel_coords(e->world->visible->x1, e->world->visible->y1,
e->world->visible->x2, e->world->visible->y2,
e->pixel);
e->scale_func(interp, e, -1, &bbox, e->pixel);
e->scrollregion_func(interp, e, e->world->total,
c->column[e->column_index]->pixel,
c->row[e->row_index]->pixel);
e->pixel->x = e->element_x(interp, e->win, 0.0);
e->pixel->y = e->element_y(interp, e->win, 0.0);
pushZoom(&e->zoom, e->world->visible);
}
void element_zoomback(Tcl_Interp *interp,
element *e)
{
d_box bbox;
int dummy;
coord *column = e->c->column[e->column_index];
coord *row = e->c->row[e->row_index];
CanvasPtr *pixel_column = NULL;
CanvasPtr *pixel_row = NULL;
box zoom;
#ifdef DEBUG
printf("element_zoomback %s\n", e->win);
#endif
if (!e->scale_func)
return;
popZoom(&e->zoom);
if (examineZoom(e->zoom) == NULL) {
return;
}
memcpy(e->world->visible, examineZoom(e->zoom), sizeof(d_box));
world_to_pixel(e->pixel, e->world->visible->x1, e->world->visible->y1,
&zoom.x1, &zoom.y1);
world_to_pixel(e->pixel, e->world->visible->x2, e->world->visible->y2,
&zoom.x2, &zoom.y2);
if (e->orientation & HORIZONTAL) {
world_to_pixel(column->pixel, column->visible.min, 0,
&zoom.x1, &dummy);
world_to_pixel(column->pixel, column->visible.max, 0,
&zoom.x2, &dummy);
}
if (e->orientation & VERTICAL) {
world_to_pixel(row->pixel, 0, row->visible.min,
&dummy, &zoom.y1);
world_to_pixel(row->pixel, 0, row->visible.max,
&dummy, &zoom.y2);
}
bbox.x1 = (double)zoom.x1;
bbox.y1 = (double)zoom.y1;
bbox.x2 = (double)zoom.x2;
bbox.y2 = (double)zoom.y2;
e->scale_func(interp, e, -1, &bbox, e->pixel);
set_pixel_coords(e->world->visible->x1, e->world->visible->y1,
e->world->visible->x2, e->world->visible->y2,
e->pixel);
if (e->orientation & HORIZONTAL) {
if (NULL == (pixel_column = (CanvasPtr *)xmalloc(sizeof(CanvasPtr))))
return;
memcpy(pixel_column, e->c->column[e->column_index]->pixel, sizeof(CanvasPtr));
set_pixel_coords(column->visible.min, 0, column->visible.max, 0,
pixel_column);
}
if (e->orientation & VERTICAL) {
if (NULL == (pixel_row = (CanvasPtr *)xmalloc(sizeof(CanvasPtr))))
return;
memcpy(pixel_row, e->c->row[e->row_index]->pixel, sizeof(CanvasPtr));
set_pixel_coords(0, row->visible.min, 0, row->visible.max,
pixel_row);
}
e->scrollregion_func(interp, e, e->world->total, pixel_column, pixel_row);
e->pixel->x = e->element_x(interp, e->win, 0.0);
e->pixel->y = e->element_y(interp, e->win, 0.0);
if (pixel_column)
xfree(pixel_column);
if (pixel_row)
xfree(pixel_row);
}
void container_zoom(Tcl_Interp *interp,
int container_id,
float amount,
int x1,
int y1,
int x2,
int y2)
{
int i, j;
container *c = get_container(container_id);
element *e;
box **zoom;
double length, dist;
/* int dummy;*/
double ddummy;
if (NULL == (zoom = (box **)xmalloc(c->num_rows * sizeof(box *))))
return;
for (i = 0; i < c->num_rows; i++) {
if (NULL == (zoom[i] = (box *)xmalloc(c->num_columns * sizeof(box))))
return;
}
for (i = 0; i < c->num_rows; i++) {
if (c->row[i]->ruler) {
if (amount != -1.0) {
length = c->row[i]->visible.max - c->row[i]->visible.min + 1;
dist = length * amount;
c->row[i]->visible.min += dist;
c->row[i]->visible.max -= dist;
} else {
pixel_to_world(c->row[i]->pixel, x1, y1,
&ddummy, &c->row[i]->visible.min);
pixel_to_world(c->row[i]->pixel, x2, y2,
&ddummy, &c->row[i]->visible.max);
}
#ifdef REMOVE
/* kfs 11/04/2003
* can't see a reason for setting zoom here, it is overwritten
* in element_zoom anyway
*/
world_to_pixel(c->row[i]->pixel, 0, c->row[i]->visible.min,
&dummy, &zoom[i][0].y1);
world_to_pixel(c->row[i]->pixel, 0, c->row[i]->visible.max,
&dummy, &zoom[i][0].y2);
#endif
set_pixel_coords(0, c->row[i]->visible.min,
0, c->row[i]->visible.max,
c->row[i]->pixel);
}
}
for (i = 0; i < c->num_columns; i++) {
if (c->column[i]->ruler) {
if (amount != -1.0) {
length = c->column[i]->visible.max - c->column[i]->visible.min + 1;
dist = length * amount;
c->column[i]->visible.min += dist;
c->column[i]->visible.max -= dist;
} else {
pixel_to_world(c->column[i]->pixel, x1, y1,
&c->column[i]->visible.min, &ddummy);
pixel_to_world(c->column[i]->pixel, x2, y2,
&c->column[i]->visible.max, &ddummy);
}
#ifdef REMOVE
/* kfs 11/04/2003
* can't see a reason for setting zoom here, it is overwritten
* in element_zoom anyway
*/
world_to_pixel(c->column[i]->pixel, c->column[i]->visible.min,
0, &zoom[0][i].x1, &dummy);
world_to_pixel(c->column[i]->pixel, c->column[i]->visible.max,
0, &zoom[0][i].x2, &dummy);
#endif
set_pixel_coords(c->column[i]->visible.min, 0,
c->column[i]->visible.max, 0,
c->column[i]->pixel);
}
}
for (i = 0; i < c->num_rows; i++) {
for (j = 0; j < c->num_columns; j++) {
if (e = c->matrix[i][j])
element_zoom(interp, e, amount, x1, y1, x2, y2);
}
}
for (i = 0; i < c->num_rows; i++) {
/* need a window, use the first! */
e = c->matrix[i][0];
if (e != NULL && e->element_y) {
c->row[i]->pixel->y = e->element_y(interp, e->win, 0.0);
push_row_zoom(&c->row[i]->zoom, c->row[i]->visible);
}
}
for (i = 0; i < c->num_columns; i++) {
/* need a window, use the first! */
e = c->matrix[0][i];
if (e != NULL && e->element_x) {
c->column[i]->pixel->x = e->element_x(interp, e->win, 0.0);
push_column_zoom(&c->column[i]->zoom, c->column[i]->visible);
}
}
for (i = 0; i < c->num_rows; i++)
xfree(zoom[i]);
xfree(zoom);
}
/* zoomback all elements in container */
void container_zoomback(Tcl_Interp *interp,
int container_id)
{
int i, j;
element *e;
container *c = get_container(container_id);
d_box *visible;
/* set visible to be previous zoom level for each row */
for (i = 0; i < c->num_rows; i++) {
if (c->row[i]->ruler) {
popZoom(&c->row[i]->zoom);
if (examineZoom(c->row[i]->zoom) == NULL) {
return;
}
visible = examineZoom(c->row[i]->zoom);
c->row[i]->visible.min = visible->y1;
c->row[i]->visible.max = visible->y2;
}
}
/* set visible to be previous zoom level for each column */
for (i = 0; i < c->num_columns; i++) {
if (c->column[i]->ruler) {
popZoom(&c->column[i]->zoom);
if (examineZoom(c->column[i]->zoom) == NULL) {
return;
}
visible = examineZoom(c->column[i]->zoom);
c->column[i]->visible.min = visible->x1;
c->column[i]->visible.max = visible->x2;
}
}
for (i = 0; i < c->num_rows; i++) {
for (j = 0; j < c->num_columns; j++) {
e = c->matrix[i][j];
if (e != NULL)
element_zoomback(interp, e);
}
}
for (i = 0; i < c->num_rows; i++) {
e = c->matrix[i][0];
if (e != NULL && e->element_y) {
c->row[i]->pixel->y = e->element_y(interp, e->win, 0.0);
set_pixel_coords(0, c->row[i]->visible.min,
0, c->row[i]->visible.max,
c->row[i]->pixel);
}
}
for (i = 0; i < c->num_columns; i++) {
e = c->matrix[0][i];
if (e != NULL && e->element_x) {
c->column[i]->pixel->x = e->element_x(interp, e->win, 0.0);
set_pixel_coords(c->column[i]->visible.min, 0,
c->column[i]->visible.max, 0,
c->column[i]->pixel);
}
}
}
d_box scale_box(element *e)
{
d_box bbox;
bbox.x1 = e->world->visible->x1;
bbox.x2 = e->world->visible->x2;
bbox.y1 = e->world->visible->y1;
bbox.y2 = e->world->visible->y2;
/* horizontal length ruler */
if (e->orientation & HORIZONTAL) {
bbox.x1 = e->c->column[e->column_index]->visible.min;
bbox.x2 = e->c->column[e->column_index]->visible.max;
}
/* vertical length ruler */
if (e->orientation & VERTICAL) {
bbox.y1 = e->c->row[e->row_index]->visible.min;
bbox.y2 = e->c->row[e->row_index]->visible.max;
}
#ifdef DEBUG
printf("scale_box %f %f %f %f\n", bbox.x1, bbox.y1, bbox.x2, bbox.y2);
#endif
return bbox;
}
void draw_container_crosshair(Tcl_Interp *interp,
int element_id,
int x,
int y)
{
int i;
element *e = get_element(element_id);
element *next;
/* draw crosshair in all elements in same column and row */
if (e->crosshair & HORIZONTAL) {
for (i = 0; i < e->c->num_rows; i++) {
next = e->c->matrix[i][e->column_index];
if (next)
e->draw_crosshair_func(interp, next, x, HORIZONTAL);
}
}
if (e->crosshair & VERTICAL) {
for (i = 0; i < e->c->num_columns; i++) {
next = e->c->matrix[e->row_index][i];
if (next)
e->draw_crosshair_func(interp, next, y, VERTICAL);
}
}
}
void delete_container_crosshair(Tcl_Interp *interp,
int element_id)
{
int i, j;
element *e = get_element(element_id);
element *next;
if (!e)
return;
for (i = 0; i < e->c->num_rows; i++) {
for (j = 0; j < e->c->num_columns; j++) {
next = e->c->matrix[i][j];
if (next != NULL)
e->delete_crosshair_func(interp, next);
}
}
}
double invert_wy (element *e,
double y)
{
return(e->world->total->y2 - y + e->world->total->y1);
}
int invert_cy (element *e,
int y)
{
return(e->pixel->height - y);
}
cursor_t *find_element_cursor(element *e,
int seq_id,
int direction)
{
int i;
for (i = 0; i < e->num_seqs; i++) {
if (e->seqs[i].seq_id == seq_id &&
e->seqs[i].direction == direction) {
return e->cursor[i];
}
}
return NULL;
}
void set_container_column_coords(Tcl_Interp *interp,
coord *column,
int x)
{
double dummy;
column->pixel->x = x;
#ifdef DEBUG
printf("set_container_column_coords %d\n", column->pixel->x);
#endif
pixel_to_world(column->pixel,
column->pixel->x, 0,
&column->visible.min, &dummy);
pixel_to_world(column->pixel,
column->pixel->x +
column->pixel->width, 0,
&column->visible.max, &dummy);
set_pixel_coords(column->visible.min, 0, column->visible.max, 0,
column->pixel);
}
int make_new_element(Tcl_Interp *interp,
int c_id,
char *c_win,
int e_id,
char *e_win,
int seq_id,
plot_data *result,
double min_x,
double max_x,
double min_y,
double max_y,
int orientation,
int crosshair,
int element_type,
element **e_new)
{
element *e;
double x0, x1, y0, y1;
if (NULL == (e = (get_element(e_id))))
e = create_element(interp, c_id, e_id, e_win, orientation, crosshair);
if (-1 == (add_result_to_element(e, result, min_x, min_y, max_x, max_y,
orientation, element_type))) {
return -1;
}
add_seq_id_to_element(e, seq_id, orientation);
x0 = min_x;
x1 = max_x;
y0 = min_y;
y1 = max_y;
if (!(orientation & HORIZONTAL)) {
x0 = INT_MAX;
x1 = INT_MIN;
}
if (!(orientation & VERTICAL)) {
y0 = INT_MAX;
y1 = INT_MIN;
}
e->world->total->x1 = min_x;
e->world->total->x2 = max_x;
e->world->total->y1 = min_y;
e->world->total->y2 = max_y;
init_pixel(interp, e, e->pixel);
add_element_to_container(interp, c_id, c_win, e, x0, x1, y0, y1);
#ifdef DEBUG
printf("COLUMN TOTAL %f %f VISIBLE %f %f\n",
e->c->column[e->column_index]->total.min,
e->c->column[e->column_index]->total.max,
e->c->column[e->column_index]->visible.min,
e->c->column[e->column_index]->visible.max);
#endif
if (orientation == HORIZONTAL) {
e->world->visible->x1 = e->c->column[e->column_index]->total.min;
e->world->visible->x2 = e->c->column[e->column_index]->total.max;
e->world->visible->y1 = e->world->total->y1;
e->world->visible->y2 = e->world->total->y2;
} else if (orientation == VERTICAL) {
e->world->visible->x1 = e->world->total->x1;
e->world->visible->x2 = e->world->total->x2;
e->world->visible->y1 = e->c->row[e->row_index]->total.min;
e->world->visible->y2 = e->c->row[e->row_index]->total.max;
} else {
e->world->visible->x1 = e->c->column[e->column_index]->total.min;
e->world->visible->x2 = e->c->column[e->column_index]->total.max;
e->world->visible->y1 = e->c->row[e->row_index]->total.min;
e->world->visible->y2 = e->c->row[e->row_index]->total.max;
}
set_pixel_coords(e->world->visible->x1, e->world->visible->y1,
e->world->visible->x2, e->world->visible->y2, e->pixel);
/* remove all current zooming info */
freeZoom(&e->zoom);
/* add first zoom */
pushZoom(&e->zoom, e->world->visible);
*e_new = e;
return 0;
}
plot_data *find_plot_data(element *e,
int result_id)
{
int i;
for (i = 0; i < e->num_results; i++) {
if (result_id == e->results[i]->result_id)
return e->results[i];
}
return NULL;
}
void move_element_to_new_container(Tcl_Interp *interp,
int old_e_id,
int new_c_id,
char *new_c_win,
int old_c_id,
char *new_e_win,
int new_e_id,
int new_orientation)
{
element *e_new;
int i;
if (NULL == (e_new = get_element(old_e_id))) {
printf("ERROR in move_element_to_new_container\n");
return;
}
delete_element_from_container(e_new);
/* add element to new container */
/* change orientation of all seqs in element */
if (new_orientation != e_new->orientation) {
for (i = 0; i < e_new->num_seqs; i++) {
e_new->seqs[i].direction = new_orientation;
}
}
e_new->win = strdup(new_e_win);
e_new->id = new_e_id;
e_new->orientation = new_orientation;
add_element_to_container(interp, new_c_id, new_c_win, e_new,
e_new->world->total->x1, e_new->world->total->x2,
e_new->world->total->y1, e_new->world->total->y2);
e_new->replot_func(e_new);
}
int get_coord_seq_ids(container *c,
int index,
int orientation,
seq_id_dir **seq_ids,
int *num_seqs) {
int i, j;
element *e;
int cnt = 0;
/* iterate down a column */
if (orientation == VERTICAL) {
/* first time round to see how much room to allocate */
for (i = 0; i < c->num_rows; i++) {
if (!(e = c->matrix[i][index]))
break;
for (j = 0; j < e->num_seqs; j++) {
if (e->seqs[j].direction == orientation)
cnt++;
}
}
if (NULL == (*seq_ids = (seq_id_dir *)xmalloc(cnt * sizeof(seq_id_dir))))
return -1;
cnt = 0;
/* fill in seq_id structure */
for (i = 0; i < c->num_rows; i++) {
if (!(e = c->matrix[i][index]))
break;
for (j = 0; j < e->num_seqs; j++) {
if (e->seqs[j].direction == orientation) {
(*seq_ids)[cnt].seq_id = e->seqs[j].seq_id;
(*seq_ids)[cnt++].direction = e->seqs[j].direction;
}
}
}
} else {
/* first time round to see how much room to allocate */
for (i = 0; i < c->num_columns; i++) {
if (!(e = c->matrix[index][i]))
break;
for (j = 0; j < e->num_seqs; j++) {
if (e->seqs[j].direction == orientation)
cnt++;
}
}
if (NULL == (*seq_ids = (seq_id_dir *)xmalloc(cnt * sizeof(seq_id_dir))))
return -1;
cnt = 0;
/* fill in seq_id structure */
for (i = 0; i < c->num_columns; i++) {
if (!(e = c->matrix[index][i]))
break;
for (j = 0; j < e->num_seqs; j++) {
if (e->seqs[j].direction == orientation) {
(*seq_ids)[cnt].seq_id = e->seqs[j].seq_id;
(*seq_ids)[cnt++].direction = e->seqs[j].direction;
}
}
}
}
*num_seqs = cnt;
return 0;
}
void element_resize(Tcl_Interp *interp,
int e_id)
{
element *e = get_element(e_id);
int x1, x2, y1, y2;
int width, height;
#ifdef DEBUG
printf("element_resize %d\n", e_id);
#endif
if (!e)
return;
x1 = e->pixel->x;
y1 = e->pixel->y;
x2 = e->pixel->x + e->pixel->width;
y2 = e->pixel->y + e->pixel->height;
width = e->element_width(interp, e->win);
height = e->element_height(interp, e->win);
if (width != e->pixel->width || height != e->pixel->height) {
e->pixel->width = width;
e->pixel->height = height;
if (e->orientation & HORIZONTAL) {
e->c->column[e->column_index]->pixel->width = width;
e->c->column[e->column_index]->pixel->height = height;
}
if (e->orientation & VERTICAL) {
e->c->row[e->row_index]->pixel->width = width;
e->c->row[e->row_index]->pixel->height = height;
}
element_zoom(interp, e, -1, x1, y1, x2, y2);
if (e->orientation & HORIZONTAL) {
set_pixel_coords(e->c->column[e->column_index]->visible.min, 0,
e->c->column[e->column_index]->visible.max, 0,
e->c->column[e->column_index]->pixel);
}
if (e->orientation & VERTICAL) {
set_pixel_coords(0, e->c->row[e->row_index]->visible.min,
0, e->c->row[e->row_index]->visible.max,
e->c->row[e->row_index]->pixel);
}
if (e->replot_func)
e->replot_func(e);
}
}
void rotate_element(element *e,
int seq_id,
int result_id)
{
int i;
container *c = e->c;
int row_index = -1;
char cmd[1024];
int row_num;
if (e->orientation == HORIZONTAL) {
/* can only rotate an element if there is a vertical ruler in the same
row */
for (i = 0; i < c->num_rows; i++) {
if (c->row[i]->ruler && c->row[i]->ruler->orientation == VERTICAL) {
row_index = i;
break;
}
}
if (row_index == -1)
return;
row_num = get_element_row(c->interp, e->win);
sprintf(cmd, "rotate_element %s %s %d %d %d %d", e->win, c->row[i]->ruler->win, seq_id, result_id, VERTICAL, row_num);
if (TCL_OK != (Tcl_Eval(c->interp, cmd)))
printf("rotate_element!!! %s\n", Tcl_GetStringResult(c->interp));
}
}
void update_container_menu(int container_id) {
int i, j;
container *c;
char cmd[1024];
if (!(c = get_container(container_id)))
return;
/* in the process of shutting down container */
if (c->status)
return;
Tcl_VarEval(c->interp, "delete_menubar ", c->win, NULL);
for (i = 0; i < c->num_rows; i++) {
for (j = 0; j < c->num_columns; j++) {
if (c->matrix[i][j]) {
sprintf(cmd, "update_container_menu %s %d %s", c->win, c->id,
c->matrix[i][j]->win);
Tcl_Eval(c->interp, cmd);
}
}
}
}
|