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
|
/* GNU polyxmass - the massist's program.
--------------------------------------
Copyright (C) 2000,2001,2002,2003,2004 Filippo Rusconi
http://www.polyxmass.org
This file is part of the "GNU polyxmass" project.
The "GNU polyxmass" project is an official GNU project package (see
www.gnu.org) released ---in its entirety--- under the GNU General
Public License and was started at the Centre National de la
Recherche Scientifique (FRANCE), that granted me the formal
authorization to publish it under this Free Software License.
This software 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 software 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 software; if not, write to the
Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "polyxmass-ui-seqed-widget-mnm-modif.h"
#include "polyxmass-ui-seqed-widget.h"
#include "polyxedit-ui-masses-display-wnd.h"
#include "polyxmass-pixbuf-rendering.h"
/************** HIGHL LEVEL GUI MONOMER MODIFICATION FUNCTIONS ***************/
GtkWidget *
polyxmass_seqed_widget_mnm_modif_wnd_setup (GtkWidget *seqed_widget)
{
GtkWidget *window = NULL;
GtkWidget *widget = NULL;
GtkTreeView *treeview = NULL;
GtkTreeSelection* selection = NULL;
PxmPolchemdefCtxt *polchemdefctxt = NULL;
PxmPolchemdef *polchemdef = NULL;
PxmEditCtxt *editctxt = NULL;
PxmMonomer *monomer = NULL;
GladeXML *xml = NULL;
gint idx = -1;
gint start = -1;
gint end = -1;
gchar *gui_file = NULL;
gchar *help = NULL;
g_assert (seqed_widget != NULL);
polchemdefctxt = PXM_SEQED_WIDGET (seqed_widget)->polchemdefctxt;
g_assert (polchemdefctxt != NULL);
polchemdef = polchemdefctxt->polchemdef;
g_assert (polchemdef != NULL);
gui_file =
g_strdup_printf ("%s/polyxedit-monomer-modif.glade", userspec->gladedir);
g_assert (gui_file != NULL);
xml = glade_xml_new (gui_file, "monomer_modif_wnd",
PACKAGE);
g_free (gui_file);
if (xml == NULL)
{
g_error (_("%s@%d: failed to load the interface\n"),
__FILE__, __LINE__);
return NULL;
}
window = glade_xml_get_widget (xml, "monomer_modif_wnd");
if (window == NULL)
{
g_critical (_("%s@%d: failed to create the monomer "
"modification window\n"),
__FILE__, __LINE__);
g_object_unref (G_OBJECT (xml));
return NULL;
}
widget = glade_xml_get_widget (xml, "messages_entry");
g_assert (widget != NULL);
g_object_set_data (G_OBJECT (window), "messages_entry",
widget);
/* IMMEDIATELY set the pointer to the seqed_widget as a datum to the
window. We will need this in function that only get the pointer
to the window.
*/
g_object_set_data (G_OBJECT (window), "seqed_widget", seqed_widget);
/* The vertical box where the polymer sequence data widgets are packed,
so that we make them invisible in one go.
*/
widget = glade_xml_get_widget (xml, "polseq_prop_vbox");
g_assert (widget != NULL);
g_object_set_data (G_OBJECT (window),
"polseq_prop_vbox", widget);
/* Are we setting up this window for a polymer sequence window, in which case we
should have a edictxt pointer datum available:
*/
editctxt = g_object_get_data (G_OBJECT (seqed_widget), "editctxt");
if (editctxt != NULL)
{
/* Set the name of the polymer sequence to its correspondent GtkEntry.
*/
widget = glade_xml_get_widget (xml, "polseq_name_entry");
g_assert (widget != NULL);
g_object_set_data (G_OBJECT (window),
"polseq_name_entry", widget);
g_assert (editctxt->polymer->plminfo->name != NULL);
gtk_entry_set_text (GTK_ENTRY (widget),
editctxt->polymer->plminfo->name);
/* Set the code of the polymer sequence to its correspondent GtkEntry.
*/
widget = glade_xml_get_widget (xml, "polseq_code_entry");
g_assert (widget != NULL);
g_object_set_data (G_OBJECT (window),
"polseq_code_entry", widget);
g_assert (editctxt->polymer->plminfo->code != NULL);
gtk_entry_set_text (GTK_ENTRY (widget),
editctxt->polymer->plminfo->code);
/* Set the identity number (actually the seqed_widget pointer) to
* its GtkEntry (this is useful when cleavages are made to identify
* unambiguously the polymer from which results are displayed).
*/
widget = glade_xml_get_widget (xml, "polseq_id_number_entry");
g_object_set_data (G_OBJECT (window),
"polseq_id_number_entry",
widget);
help = g_strdup_printf ("%p", seqed_widget);
gtk_entry_set_text (GTK_ENTRY (widget), help);
g_free (help);
}
else
{
/* We just hide the stuff there.
*/
gtk_widget_hide (widget);
}
/* Now deal systematically with the widgets that we will use later.
*/
widget = glade_xml_get_widget (xml,
"selected_monomer_code_entry");
g_object_set_data (G_OBJECT (window),
"selected_monomer_code_entry",
widget);
widget = glade_xml_get_widget (xml,
"selected_monomer_position_entry");
g_object_set_data (G_OBJECT (window),
"selected_monomer_position_entry",
widget);
widget = glade_xml_get_widget (xml,
"available_modifications_treeview");
g_object_set_data (G_OBJECT (window),
"available_modifications_treeview",
widget);
widget = glade_xml_get_widget (xml,
"target_selected_monomer_radiobutton");
g_object_set_data (G_OBJECT (window),
"target_selected_monomer_radiobutton",
widget);
widget = glade_xml_get_widget (xml,
"target_monomers_same_code_radiobutton");
g_object_set_data (G_OBJECT (window),
"target_monomers_same_code_radiobutton",
widget);
widget = glade_xml_get_widget (xml,
"target_monomers_from_list_radiobutton");
g_object_set_data (G_OBJECT (window),
"target_monomers_from_list_radiobutton",
widget);
widget = glade_xml_get_widget (xml,
"target_all_monomers_radiobutton");
g_object_set_data (G_OBJECT (window),
"target_all_monomers_radiobutton",
widget);
widget = glade_xml_get_widget (xml,
"target_monomers_spec_pos_radiobutton");
g_object_set_data (G_OBJECT (window),
"target_monomers_spec_pos_radiobutton",
widget);
widget = glade_xml_get_widget (xml,
"target_monomers_spec_pos_entry");
g_object_set_data (G_OBJECT (window),
"target_monomers_spec_pos_entry",
widget);
widget = glade_xml_get_widget (xml,
"target_monomers_treeview");
g_object_set_data (G_OBJECT (window),
"target_monomers_treeview",
widget);
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget));
gtk_tree_selection_set_mode (selection, GTK_SELECTION_MULTIPLE);
/* The textview where errors are to be displayed.
*/
widget = glade_xml_get_widget (xml,
"monomer_modification_errors_textview");
g_object_set_data (G_OBJECT (window),
"monomer_modification_errors_textview",
widget);
/* The buttons are connected through signals to related functions.
*/
widget =
glade_xml_get_widget (xml, "monomer_modification_modify_button");
g_object_set_data (G_OBJECT (window),
"monomer_modification_modify_button",
widget);
g_signal_connect (G_OBJECT (widget),
"clicked",
G_CALLBACK (polyxmass_seqed_widget_mnm_modif_wnd_modify_button),
window);
widget =
glade_xml_get_widget (xml, "monomer_modification_un_modify_button");
g_object_set_data (G_OBJECT (window),
"monomer_modification_un_modify_button",
widget);
g_signal_connect (G_OBJECT (widget),
"clicked",
G_CALLBACK (polyxmass_seqed_widget_mnm_modif_wnd_un_modify_button),
window);
gtk_widget_show_all (GTK_WIDGET (window));
/* We have finished setting up the window, and so also using
* the xml data, unref them
*/
g_object_unref (G_OBJECT (xml));
/* And now that we know all the window is set up, we can fill the
data in it: the list of available modifications, the list of the
monomers in the polymer chemistry definition context, the
position of the possibly selected monomer...
*/
/* First the index of the currently selected monomer. Function returns
a pointer to a monomer if only one is selected, and the index
of the selected monomer into idx.
*/
idx = -1;
monomer = polyxmass_seqed_widget_get_selected_monomer (seqed_widget, &idx);
if (monomer != NULL)
{
/* If a single monomer is selected, then its idx cannot be -1.
*/
g_assert (idx != -1);
/* We can print the relevant info in their entries.
*/
widget = g_object_get_data (G_OBJECT (window),
"selected_monomer_code_entry");
g_assert (widget != NULL);
gtk_entry_set_text (GTK_ENTRY (widget), monomer->code);
/* Print the position of the selected monomer, not its index.
*/
help = g_strdup_printf ("%d", idx + 1);
widget = g_object_get_data (G_OBJECT (window),
"selected_monomer_position_entry");
g_assert (widget != NULL);
gtk_entry_set_text (GTK_ENTRY (widget), help);
g_free (help);
}
else
{
/* We can print the relevant explanations the entry.
*/
widget = g_object_get_data (G_OBJECT (window),
"selected_monomer_code_entry");
g_assert (widget != NULL);
gtk_entry_set_text (GTK_ENTRY (widget),
_("Not a single monomer selected"));
/* Get the indices of the selection if there is one.
*/
if (FALSE !=
polyxmass_seqed_widget_get_selection_indices (seqed_widget,
&start, &end))
{
/* Remember that due to the handling of the polymer sequence
displayed in the sequence editor, the end value that is
returned is indeed corresponding to the real index of the last
selected monomer + 1, so care should be taken not to outbound
the polymer sequence array.
*/
/* We show the (start + 1) value because we want to show
a position and not an index.
*/
help =
g_strdup_printf ("[%d..%d]", start + 1, end /* NOT + 1 */);
/* Print the position of the selection, not its index.
*/
widget = g_object_get_data (G_OBJECT (window),
"selected_monomer_position_entry");
g_assert (widget != NULL);
gtk_entry_set_text (GTK_ENTRY (widget), help);
g_free (help);
}
else
{
/* Print that there is no selection.
*/
widget = g_object_get_data (G_OBJECT (window),
"selected_monomer_position_entry");
g_assert (widget != NULL);
gtk_entry_set_text (GTK_ENTRY (widget), _("No selection"));
}
/* Note that if there is no single monomer selected, it makes no
sense to have the radio button "target_selected_monomer_radiobutton"
selected. We set it to the other one, where the user selects the
positions with regex-like strings.
*/
widget = g_object_get_data (G_OBJECT (window),
"target_monomers_spec_pos_radiobutton");
g_assert (widget != NULL);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
}
/* Second fill the treeview of modifications avaialable to the
polymer chemistry definition context of that specific polymer
sequence.
*/
treeview =
GTK_TREE_VIEW (g_object_get_data (G_OBJECT (window),
"available_modifications_treeview"));
if (FALSE ==
polyxmass_seqed_widget_mnm_modif_wnd_setup_modifs_treeview (treeview,
polchemdef))
{
g_critical (_("%s@%d: failed to fill the modifications list\n"),
__FILE__, __LINE__);
}
/* Third fill the treeview of all the monomer codes present in the
polymer chemistry definition context of that specific polymer
sequence.
*/
treeview =
GTK_TREE_VIEW (g_object_get_data (G_OBJECT (window),
"target_monomers_treeview"));
if (FALSE ==
polyxmass_seqed_widget_mnm_modif_wnd_setup_monomcodes_treeview (treeview,
polchemdef))
{
g_critical (_("%s@%d: failed to fill the monomer codes list\n"),
__FILE__, __LINE__);
}
/* The signal of the window itself.
*/
/* Signal / callback connections.
*/
g_signal_connect
(G_OBJECT (window),
"delete_event",
G_CALLBACK (polyxmass_seqed_widget_mnm_modif_wnd_delete_event),
seqed_widget);
g_signal_connect
(G_OBJECT (window),
"destroy_event",
G_CALLBACK (polyxmass_seqed_widget_mnm_modif_wnd_destroy_event),
seqed_widget);
/* Set this window pointer as a full datum to the polymer sequence
editor window, so that when it is closed this window is closed
also.
There might be more than one monomer modification window opened
for a given polymer seqence editing window, and we do not want
that the second window destroys the datum name of the first
window, so we create an uambiguous datum name each time.
*/
help = g_strdup_printf ("monomer_modif_wnd-%p", window);
g_object_set_data_full
(G_OBJECT (seqed_widget),
help, GTK_WIDGET (window),
(GDestroyNotify) polyxmass_seqed_widget_mnm_modif_wnd_really_close);
g_free (help);
return window;
}
gboolean
polyxmass_seqed_widget_mnm_modif_wnd_setup_modifs_treeview (GtkTreeView *treeview,
PxmPolchemdef *polchemdef)
{
GPtrArray *GPA = NULL;
GtkCellRenderer *renderer = NULL;
GtkListStore *model;
GtkTreeIter tree_iter;
gint iter = 0;
PxmModif *modif;
g_assert (polchemdef != NULL);
GPA = polchemdef->modifGPA;
/* Create the list store.
*/
model = gtk_list_store_new (COLUMN_MDF_COL_COUNT, /*Numb. of columns*/
G_TYPE_STRING,
G_TYPE_STRING,
G_TYPE_BOOLEAN /* editability */);
/* Add the items if GPA is non-null and there are items in it.
*/
if (GPA != NULL)
{
for (iter = 0 ; iter < GPA->len ; iter++)
{
/* Acquire an iterator.
*/
gtk_list_store_append (model, &tree_iter);
modif = g_ptr_array_index (GPA, iter);
gtk_list_store_set (model, &tree_iter,
COLUMN_MDF_NAME,
modif->name,
COLUMN_MDF_ACTFORM,
modif->actform,
COLUMN_MDF_EDITABLE, FALSE,
-1);
}
}
gtk_tree_view_set_model (treeview, GTK_TREE_MODEL (model));
g_object_unref (G_OBJECT (model));
gtk_tree_selection_set_mode (gtk_tree_view_get_selection
(GTK_TREE_VIEW (treeview)),
GTK_SELECTION_SINGLE);
/* Modif Name column.
*/
renderer = gtk_cell_renderer_text_new ();
/*
GtkTreeViewColumn *column = NULL;
column =
gtk_tree_view_column_new_with_attributes (_("Name"),
renderer,
"text", COLUMN_MDF_NAME,
NULL);
gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
*/
gtk_tree_view_insert_column_with_attributes
(GTK_TREE_VIEW (treeview),
-1, _("Name"), renderer,
"text", COLUMN_MDF_NAME,
"editable", COLUMN_MDF_EDITABLE,
NULL);
g_object_set_data (G_OBJECT (renderer), "column",
(gint *) COLUMN_MDF_NAME);
/* Modif Actform column.
*/
renderer = gtk_cell_renderer_text_new ();
gtk_tree_view_insert_column_with_attributes
(GTK_TREE_VIEW (treeview),
-1, _("Actform"), renderer,
"text", COLUMN_MDF_ACTFORM,
"editable", COLUMN_MDF_EDITABLE,
NULL);
g_object_set_data (G_OBJECT (renderer), "column",
(gint *) COLUMN_MDF_ACTFORM);
return TRUE;
}
gboolean
polyxmass_seqed_widget_mnm_modif_wnd_setup_monomcodes_treeview (GtkTreeView *treeview,
PxmPolchemdef *polchemdef)
{
GPtrArray *GPA = NULL;
GtkCellRenderer *renderer = NULL;
GtkListStore *model;
GtkTreeIter tree_iter;
gint iter = 0;
PxmMonomer *monomer;
g_assert (polchemdef != NULL);
GPA = polchemdef->monomerGPA;
/* Create the list store.
*/
model = gtk_list_store_new (COLUMN_MNM_COL_COUNT, /*Numb. of columns*/
G_TYPE_STRING, /* monomer name */
G_TYPE_STRING, /* monomer code */
G_TYPE_STRING /* monomer formula */,
G_TYPE_BOOLEAN /* editability */);
/* Add the items if GPA is non-null and there are items in it.
*/
if (GPA != NULL)
{
for (iter = 0 ; iter < GPA->len ; iter++)
{
/* Acquire an iterator.
*/
gtk_list_store_append (model, &tree_iter);
monomer = g_ptr_array_index (GPA, iter);
g_assert (monomer != NULL);
gtk_list_store_set (model, &tree_iter,
COLUMN_MNM_NAME,
monomer->name,
COLUMN_MNM_CODE,
monomer->code,
COLUMN_MNM_FORMULA,
monomer->formula,
COLUMN_MNM_EDITABLE, FALSE,
-1);
}
}
gtk_tree_view_set_model (treeview, GTK_TREE_MODEL (model));
g_object_unref (G_OBJECT (model));
gtk_tree_selection_set_mode (gtk_tree_view_get_selection
(GTK_TREE_VIEW (treeview)),
GTK_SELECTION_MULTIPLE);
/* Monomer Name column.
*/
renderer = gtk_cell_renderer_text_new ();
/*
GtkTreeViewColumn *column = NULL;
column =
gtk_tree_view_column_new_with_attributes (_("Name"),
renderer,
"text", COLUMN_MNM_NAME,
NULL);
gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
*/
gtk_tree_view_insert_column_with_attributes
(GTK_TREE_VIEW (treeview),
-1, _("Name"), renderer,
"text", COLUMN_MNM_NAME,
"editable", COLUMN_MNM_EDITABLE,
NULL);
g_object_set_data (G_OBJECT (renderer), "column",
(gint *) COLUMN_MNM_NAME);
/* Monomer Code column.
*/
renderer = gtk_cell_renderer_text_new ();
gtk_tree_view_insert_column_with_attributes
(GTK_TREE_VIEW (treeview),
-1, _("Code"), renderer,
"text", COLUMN_MNM_CODE,
"editable", COLUMN_MNM_EDITABLE,
NULL);
g_object_set_data (G_OBJECT (renderer), "column",
(gint *) COLUMN_MNM_CODE);
/* Monomer Formula column.
*/
renderer = gtk_cell_renderer_text_new ();
gtk_tree_view_insert_column_with_attributes
(GTK_TREE_VIEW (treeview),
-1, _("Formula"), renderer,
"text", COLUMN_MNM_FORMULA,
"editable", COLUMN_MNM_EDITABLE,
NULL);
g_object_set_data (G_OBJECT (renderer), "column",
(gint *) COLUMN_MNM_FORMULA);
return TRUE;
}
void
polyxmass_seqed_widget_mnm_modif_wnd_modify_button (GtkWidget *button,
gpointer data)
{
GtkWidget *window = data;
GtkWidget *seqed_widget = NULL;
gint pos_count = -1;
gint full_success = 0;
gint render_failure = 0;
gint full_failure = 0;
gint chem_failure = 0;
GtkTreeView * treeview = NULL;
GtkTreeIter treeiter;
GtkTreeSelection* selection = NULL;
GtkTreeModel *model = NULL;
GtkTextView *textview = NULL;
GtkTextIter text_iter;
GtkTextBuffer *buffer = NULL;
GArray *GA = NULL;
gchar *modif_name = NULL;
gchar *errors = NULL;
gchar *help = NULL;
g_assert (window != NULL);
seqed_widget = g_object_get_data (G_OBJECT (window), "seqed_widget");
g_assert (seqed_widget != NULL);
treeview = g_object_get_data (G_OBJECT (window),
"available_modifications_treeview");
/* Ensure right away that there is one modification selected.
*/
model = gtk_tree_view_get_model (treeview);
g_assert (model != NULL);
selection = gtk_tree_view_get_selection (treeview);
if (FALSE == gtk_tree_selection_get_selected (selection,
NULL,
&treeiter))
{
polyxmass_timeoutmsg_message_set
((GtkWindow *) window,
_("Select a modification to apply"),
POLYXMASS_NORM_MSG_TIMEOUT);
return; /*no selection, just return. */
}
/* At this point treeiter points to the selected item in the treeview.
This means that we must get the name out of the item.
*/
/* Make sure you terminate calls to gtk_tree_model_get()
with a '-1' value. We can do this call because we have the treeiter
pointing to the selected node!
*/
gtk_tree_model_get (model, &treeiter,
COLUMN_MDF_NAME, &modif_name,
-1);
g_assert (modif_name != NULL); /* Free it later.*/
/* We now have the name of the modif that is selected in the
treeview. We can go on and allocate the GArray that will hold
all the positions where the modification has to occur. These
positions will be analyzed in another function.
*/
GA = g_array_new (TRUE, TRUE, (guint) sizeof (gint));
pos_count =
polyxmass_seqed_widget_mnm_modif_wnd_prepare_indices_array (window,
GA);
if (-1 == pos_count)
return;
/*
debug_printf (("number of positions to modify: %d\n", pos_count));
*/
/* At this stage we have an array of integers that represent all the
indices at which the monomers of the polymer sequence should be
modified using the modification that we got previously in the
modif_name variable (see above). Time has come to perform the
modification proper.
*/
polyxmass_seqed_widget_mnm_modif_modify_monomer_GA (GA,
modif_name,
seqed_widget,
&errors,
&full_success,
&full_failure,
&chem_failure,
&render_failure);
g_free (modif_name);
/* If at least one chemical modification was performed, irrespective
of the graphical rendering, the polymer sequence is modified.
*/
if (render_failure != 0 || chem_failure != 0 || full_success != 0)
{
polyxmass_seqed_widget_signal_sequence_modified (PXM_SEQED_WIDGET (seqed_widget),
TRUE);
}
help = g_strdup_printf (_("Full success = %d; Full failure = %d; "
"Chem failure = %d; Render failure = %d"),
full_success, full_failure,
chem_failure, render_failure);
polyxmass_timeoutmsg_message_set ((GtkWindow *) window,
help,
POLYXMASS_LONG_MSG_TIMEOUT);
g_free (help);
/* If we got a string back in errors of length > 0, display its
contents in the errors textview.
*/
if (errors != NULL)
{
textview = g_object_get_data (G_OBJECT (window),
"monomer_modification_errors_textview");
g_assert (textview != NULL);
buffer = gtk_text_view_get_buffer (textview);
/* Get start of buffer.
*/
gtk_text_buffer_get_iter_at_offset (buffer, &text_iter, 0);
gtk_text_buffer_insert (buffer, &text_iter, errors, -1);
g_free (errors);
}
/* Finally free the whole indices' GArray.
*/
g_array_free (GA, TRUE);
/* The selection polygon (if there was any around monomer(s) which
have been modified) may have been partically "overwritten".
*/
polyxmass_seqed_widget_update_sel_polygon (seqed_widget);
/* The sequence and the selection.
*/
polyxmass_seqed_widget_signal_mass_update_required (PXM_SEQED_WIDGET (seqed_widget),
PXM_MASSCALC_TARGET_BOTH);
return;
}
void
polyxmass_seqed_widget_mnm_modif_wnd_un_modify_button (GtkWidget *button,
gpointer data)
{
GtkWidget *window = data;
GtkWidget *seqed_widget = NULL;
gint pos_count = -1;
gint full_success = 0;
gint render_failure = 0;
gint full_failure = 0;
gint chem_failure = 0;
GtkTreeView * treeview = NULL;
GtkTreeIter treeiter;
GtkTreeSelection* selection = NULL;
GtkTreeModel *model = NULL;
GtkTextView *textview = NULL;
GtkTextIter text_iter;
GtkTextBuffer *buffer = NULL;
GArray *GA = NULL;
gchar *modif_name = NULL;
gchar *errors = NULL;
gchar *help = NULL;
g_assert (window != NULL);
seqed_widget = g_object_get_data (G_OBJECT (window), "seqed_widget");
g_assert (seqed_widget != NULL);
treeview = g_object_get_data (G_OBJECT (window),
"available_modifications_treeview");
/* Check if there is one modification selected. Indeed, the
processing here is a bit different than for the modification:
there can be no modification selected. If such is the case, that
means that the un-modification processing will be performed
whatever the current modification of the target monomers as
determined later by the call to
polyxmass_seqed_widget_mnm_modif_wnd_prepare_indices_array (). Instead, if
a modification is selected, then the un-modification will only
effectively be performed on the monomers from the indices GArray
that are modified with this modification precisely.
*/
model = gtk_tree_view_get_model (treeview);
g_assert (model != NULL);
selection = gtk_tree_view_get_selection (treeview);
if (FALSE == gtk_tree_selection_get_selected (selection,
NULL,
&treeiter))
{
/* No modification is selected. The un-modification will be
performed on absolutely all the monomers at the indices
obtained by calling
polyxmass_seqed_widget_mnm_modif_wnd_prepare_indices_array ().
*/
}
else
{
/* At this point treeiter points to the selected item in the treeview.
This means that we must get the name out of the item.
*/
/* Make sure you terminate calls to gtk_tree_model_get()
with a '-1' value. We can do this call because we have the treeiter
pointing to the selected node!
*/
gtk_tree_model_get (model, &treeiter,
COLUMN_MDF_NAME, &modif_name,
-1);
g_assert (modif_name != NULL); /* Free it later.*/
}
/* Now modif_name is either NULL or points to an allocated string
containing the modification name.
*/
/* We now have the name of the modif that is selected in the
treeview. We can go on and allocate the GArray that will hold
all the positions where the modification has to occur. These
positions will be analyzed in another function.
*/
GA = g_array_new (TRUE, TRUE, (guint) sizeof (gint));
pos_count =
polyxmass_seqed_widget_mnm_modif_wnd_prepare_indices_array (window,
GA);
if (-1 == pos_count)
return;
/*
debug_printf (("number of positions to un-modify: %d\n", pos_count));
*/
/* At this stage we have an array of integers that represent all the
indices at which the monomers of the polymer sequence should be
modified using the modification that we got previously in the
modif_name variable (see above). Time has come to perform the
modification proper.
*/
polyxmass_seqed_widget_mnm_modif_un_modify_monomer_GA (GA,
modif_name,
seqed_widget,
&errors,
&full_success,
&full_failure,
&chem_failure,
&render_failure);
if (modif_name != NULL)
g_free (modif_name);
/* If at least one chemical modification was performed, irrespective
of the graphical rendering, the polymer sequence is modified.
*/
if (render_failure != 0 || chem_failure != 0 || full_success != 0)
polyxmass_seqed_widget_signal_sequence_modified (PXM_SEQED_WIDGET (seqed_widget),
TRUE);
/*
old
polyxedit_seqed_wnd_set_polymer_modified (editctxt, TRUE);
*/
help = g_strdup_printf (_("Full success = %d; Full failure = %d; "
"Chem failure = %d; Render failure = %d"),
full_success, full_failure,
chem_failure, render_failure);
polyxmass_timeoutmsg_message_set ((GtkWindow *) window,
help,
POLYXMASS_NORM_MSG_TIMEOUT);
g_free (help);
/* If we got a string back in errors of length > 0, display its
contents in the errors textview.
*/
if (errors != NULL)
{
textview = g_object_get_data (G_OBJECT (window),
"monomer_modification_errors_textview");
g_assert (textview != NULL);
buffer = gtk_text_view_get_buffer (textview);
/* Get start of buffer.
*/
gtk_text_buffer_get_iter_at_offset (buffer, &text_iter, 0);
gtk_text_buffer_insert (buffer, &text_iter, errors, -1);
g_free (errors);
}
/* Finally free the whole indices' GArray.
*/
g_array_free (GA, TRUE);
/* The selection polygon (if there was any around monomer(s) which
have been modified) may have been partically "overwritten".
*/
polyxmass_seqed_widget_update_sel_polygon (seqed_widget);
/* The sequence and the selection.
*/
polyxmass_seqed_widget_signal_mass_update_required (PXM_SEQED_WIDGET (seqed_widget),
PXM_MASSCALC_TARGET_BOTH);
return;
}
gint
polyxmass_seqed_widget_mnm_modif_wnd_prepare_indices_array (GtkWidget *window,
GArray *GA)
{
gint iter = 0;
gint max = 0;
gint target = -1;
gboolean valid = FALSE;
gboolean selected = FALSE;
gchar *code = NULL;
gchar *text = NULL;
GtkWidget *entry = NULL;
GtkTreeView * treeview = NULL;
GtkTreeSelection* selection = NULL;
GtkTreeIter treeiter;
GtkTreeModel *model = NULL;
GPtrArray *monomerGPA = NULL;
PxmMonomer *monomer_iter = NULL;
PxmMonomer *monomer_sel = NULL;
PxmSeqedWidget *seqed_widget = NULL;
g_assert (window != NULL);
g_assert (GA != NULL);
seqed_widget = g_object_get_data (G_OBJECT (window),
"seqed_widget");
g_assert (seqed_widget != NULL);
monomerGPA = PXM_SEQED_WIDGET (seqed_widget)->polymer->monomerGPA;
g_assert (monomerGPA != NULL);
/* Get the target of the modification operation.
*/
target = polyxmass_seqed_widget_mnm_modif_wnd_get_target (window);
if (target == MODIF_TARGET_ALL_MONOMERS)
{
/* Each single monomer in the sequence must be modified! Thus
put in the array of all the monomer indices for which
modification should occur all the indices of the polymer! That
is so easy!
*/
for (iter = 0; iter < monomerGPA->len; iter++)
GA = g_array_append_val (GA, iter);
}
else if (target == MODIF_TARGET_SEL_MONOMER
|| target == MODIF_TARGET_ALL_MONOMERS_CODE)
{
/* Modification should be applied on the selected monomer or on
all the monomers of the sequence that have the same code as
the selected one. Which means for both cases only one monomer
should currently be selected in the sequence editor. Reuse
the iter variable to get the index of the putatively selected
monomer: that's recycling!
*/
iter = -1;
monomer_sel = polyxmass_seqed_widget_get_selected_monomer (GTK_WIDGET (seqed_widget),
&iter);
if (monomer_sel == NULL)
{
polyxmass_timeoutmsg_message_set ((GtkWindow *) window,
_("Select a single monomer"),
POLYXMASS_NORM_MSG_TIMEOUT);
return -1;
}
/* A selected monomer may not have an index = -1. Good sanity
check.
*/
g_assert (iter != -1);
/* We can handle the modification right away.
*/
if (target == MODIF_TARGET_SEL_MONOMER)
{
/* Only the monomer that is currently selected should be
modified. And we just finished getting its index, so that
we can put it in the array of the indices (actually one
only in our present case) of the monomers to be modified.
*/
GA = g_array_append_val (GA, iter);
}
/* If it is not SEL_MONOMER, then it is ALL_MONOMERS_CODE!
*/
else
{
/* All monomers that have the same code as the one which is
currently selected should be modified. We have the code
right away because we have the monomer!
*/
/* Iterate in the polymer sequence and for each monomer
check if it has the same code as the one we have at
hand. If so, just add the index to the array of positions
that should be modified.
*/
for (iter = 0; iter < monomerGPA->len; iter++)
{
monomer_iter = g_ptr_array_index (monomerGPA, iter);
if (0 == strcmp (monomer_sel->code, monomer_iter->code))
GA = g_array_append_val (GA, iter);
}
}
}
/* end of
else if (target == MODIF_TARGET_SEL_MONOMER
|| target == MODIF_TARGET_ALL_MONOMERS_CODE)
*/
else if (target == MODIF_TARGET_ALL_MONOMERS_LIST)
{
/* The code(s) of the monomers for which the modification
* is to be applied is(are) currently selected in the
* codes' treeview. We'll have to check that the list actually
* contains selected items:
*/
/* Get the treeview widget in which the user may select no/one/more
monomer to be modified.
*/
treeview = g_object_get_data (G_OBJECT (window),
"target_monomers_treeview");
model = gtk_tree_view_get_model (treeview);
g_assert (model != NULL);
/* Remember that we have a multiple-selection treeview here,
conversely to what was for the modification treeview. This is
why we cannot ask for the selection as we did in the modif
treeview code above.
*/
selection = gtk_tree_view_get_selection (treeview);
g_assert (selection != NULL);
/* Get the first treeiter in the list.
*/
valid = gtk_tree_model_get_iter_first (model, &treeiter);
while (valid)
{
/* Walk through the treeveiw list of monomers , reading each
row, only if actually selected.
*/
selected = gtk_tree_selection_iter_is_selected (selection,
&treeiter);
if (selected != TRUE)
{
/* Go the the next treeview item.
*/
valid = gtk_tree_model_iter_next (model, &treeiter);
continue;
}
/* The row is selected, thus we can ask that the contents of
the CODE column be allocated in 'code'. Make sure to
terminate the call to gtk_tree_model_get() * with a '-1'
value.
*/
gtk_tree_model_get (model, &treeiter,
COLUMN_MNM_CODE, &code,
-1);
/* We have a monomer code allocated in code, that we should
compare with the monomer code of each monomer iterated in
the polymer's monomerGPA array. If there is a match
that means that the iter value should be stored in the
array of all the positions where the modification should
occur.
*/
for (iter = 0; iter < monomerGPA->len; iter++)
{
monomer_iter = g_ptr_array_index (monomerGPA, iter);
if (0 == strcmp (monomer_iter->code, code))
GA = g_array_append_val (GA, iter);
}
/* Finished doing the comparison work with the currently
iterated list's monomer code 'code'. We have to free it
because the gtk_tree_model_get () call above allocated it.
*/
g_free (code);
/* And now go the the next treeview item.
*/
valid = gtk_tree_model_iter_next (model, &treeiter);
}
}
/* end of
else if (target == MODIF_TARGET_ALL_MONOMERS_LIST)
*/
else if (target == MODIF_TARGET_SPEC_POS_MONOMERS)
{
/* The user should have written some positions in the entry.
*/
entry = g_object_get_data (G_OBJECT (window),
"target_monomers_spec_pos_entry");
g_assert (entry != NULL);
text = gtk_editable_get_chars (GTK_EDITABLE (entry), 0, -1);
g_assert (text != NULL);
/* We should make sure that there is no single
space/tab/whatever character in the string that we got.
*/
text = libpolyxmass_globals_unspacify_string (&text);
if (strlen (text) <= 0)
{
polyxmass_timeoutmsg_message_set ((GtkWindow *) window,
_("Enter valid position(s)"),
POLYXMASS_NORM_MSG_TIMEOUT);
g_free (text);
return -1;
}
max = PXM_SEQED_WIDGET (seqed_widget)->polymer->monomerGPA->len - 1;
if (-1 == libpolyxmass_globals_fill_int_array_match_exp (text, GA, max))
g_critical (_("%s@%d: failed to process string: '%s'\n"),
__FILE__, __LINE__, text);
g_free (text);
}
/* end of
else if (target == MODIF_TARGET_SPEC_POS_MONOMERS)
*/
return GA->len;
}
gint
polyxmass_seqed_widget_mnm_modif_wnd_get_target (GtkWidget *window)
{
GSList *group = NULL;
GtkWidget *radio = NULL;
GSList *iter = NULL;
g_assert (window != NULL);
radio = g_object_get_data (G_OBJECT (window),
"target_selected_monomer_radiobutton");
g_assert (radio != NULL);
group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio));
iter = group;
while (iter != NULL)
{
radio = iter->data;
if (TRUE ==
gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (radio)))
{
if (0 == strcmp ("target_selected_monomer_radiobutton",
gtk_widget_get_name (GTK_WIDGET (radio))))
return MODIF_TARGET_SEL_MONOMER;
else if (0 == strcmp ("target_monomers_same_code_radiobutton",
gtk_widget_get_name (GTK_WIDGET (radio))))
return MODIF_TARGET_ALL_MONOMERS_CODE;
else if (0 == strcmp ("target_monomers_from_list_radiobutton",
gtk_widget_get_name (GTK_WIDGET (radio))))
return MODIF_TARGET_ALL_MONOMERS_LIST;
else if (0 == strcmp ("target_all_monomers_radiobutton",
gtk_widget_get_name (GTK_WIDGET (radio))))
return MODIF_TARGET_ALL_MONOMERS;
else if (0 == strcmp ("target_monomers_spec_pos_radiobutton",
gtk_widget_get_name (GTK_WIDGET (radio))))
return MODIF_TARGET_SPEC_POS_MONOMERS;
else
g_warning (_("%s@%d: failed to get the radiobutton widget\n"),
__FILE__, __LINE__);
}
iter = g_slist_next (iter);
}
return -1;
}
/************** LOW LEVEL NON-GUI MONOMER MODIFICATION FUNCTIONS ***************/
PxmModifRes
polyxmass_seqed_widget_mnm_modif_modify_monomer (PxmMonomer *mnm,
gint idx,
gchar *modif,
GtkWidget *seqed_widget)
{
GdkPixbuf *pixbuf = NULL;
PxmMonomer *monomer = NULL;
PxmPolymer *polymer = NULL;
PxmPolchemdefCtxt *polchemdefctxt = NULL;
PxmPolchemdef *polchemdef = NULL;
PxmMonicon *monicon_old = NULL;
PxmMonicon *monicon_new = NULL;
g_assert (modif != NULL);
g_assert (seqed_widget != NULL);
polchemdefctxt = PXM_SEQED_WIDGET (seqed_widget)->polchemdefctxt;
g_assert (polchemdefctxt != NULL);
polchemdef = polchemdefctxt->polchemdef;
g_assert (polchemdef != NULL);
polymer = PXM_SEQED_WIDGET (seqed_widget)->polymer;
g_assert (polymer != NULL);
/* Modifying a monomer is a two-step process: first the monomer must be
chemically modified, and next, if the modification is successful,
the graphical rendering must be performed so that the modification
can be visualized in the sequence editor.
*/
/* Sanity checks pertaining to the size of the polymer sequence.
*/
g_assert (polymer->monomerGPA->len > 0);
g_assert (idx >= 0);
g_assert (idx <= polymer->monomerGPA->len - 1);
/* Make sure we can correctly access the monomer to be modified.
*/
if (mnm == NULL)
monomer = g_ptr_array_index (polymer->monomerGPA, idx);
else
monomer = mnm;
g_assert (monomer != NULL);
/* Make sure the modif object is known to the polchemdef.
*/
if (-1 == pxmchem_modif_get_index_by_name (modif, polchemdef->modifGPA))
{
g_critical (_("%s@%d: modif is not known to the polchemdef: '%s'\n"),
__FILE__, __LINE__, modif);
return MODIF_CHEM_N_RENDER_N;
}
/* If the monomer is already modified somehow, the function below
cleanly unmodifies it prior to modifying it with 'modif'. Note
that the function below only does non-graphics stuff. We'll have
to manage the rendering below.
*/
if (FALSE == pxmchem_monomer_modify (monomer, modif))
{
g_critical (_("%s@%d: failed to modify monomer at index: '%d' "
"with modif: '%s'\n"),
__FILE__, __LINE__, idx, modif);
return MODIF_CHEM_N_RENDER_N;
}
/* At this point the chemical modification went ok, so we can manage
the rendering process. In a prudent way of doing things, we start
by making the new rendered monicon, and if everything goes well
we make the replacement, otherwise we leave the current monicon
in place but issue a critical message.
*/
/* Render a new pixbuf corresponding to the modified monomer.
*/
pixbuf =
polyxmass_pixbuf_rendering_render_modif (monomer->code,
modif,
PXM_SEQED_WIDGET (seqed_widget)->monicon_size,
&(PXM_SEQED_WIDGET (seqed_widget)->pixbufGData),
polchemdefctxt);
if (pixbuf == NULL)
{
g_critical (_("%s@%d: failed to render monicon for monomer: '%s' "
"at index: '%d' with modif: '%s'. Chemical modification "
"was performed ok, however.\n"),
__FILE__, __LINE__, monomer->code, idx, modif);
return MODIF_CHEM_Y_RENDER_N;
}
/* Now that we have the pixbuf, we can allocate the new monicon so that
a new canvas_item is prepared later.
*/
monicon_new = polyxmass_monicon_new ();
if (FALSE == polyxmass_pixbuf_rendering_monicon_make_canvas_item (monicon_new,
PXM_SEQED_WIDGET (seqed_widget)->
monicon_size,
pixbuf,
idx,
seqed_widget))
{
g_critical (_("%s@%d: failed to make canvas_item for monomer code: '%s' "
"at index: '%d', with modif: '%s'. Chemical modification "
"was performed ok, however.\n"),
__FILE__, __LINE__, monomer->code, idx, modif);
return MODIF_CHEM_Y_RENDER_N ;
}
/* At this point, the pixbuf that we got in the first place, with
the call to polyxmass_pixbuf_rendering_render_no_modif() got
referenced by the gnome_canvas_item_new() that makes the canvas
item in the polyxmass_pixbuf_rendering_monicon_make_canvas_item()
call. Thus, when we call the pxm_monicon_free() function on the
monicon, it should just
gtk_object_destroy(GTK_OBJECT(monicon->canvas_item));
which will unref the pixbuf contained in it.
So, the story goes :
1. we get a pixbuf (either pre-existing or allocated anew) with
no reference count incrementing.
2. we construct a canvas_item by using it, which increments its
reference count by 1.
3. we put that pixbuf into a monicon object that will contain it
up to its freeing.
4. some day we free the monicon, which will gtk_object_destroy
the canvas_item, which will decrement the reference count by
1. At this stage we get a reference count identical to the
situation in point 1.
*/
/* Apparently we succeeded in all our attempts, so get the pointer
to the monicon that currently renders the monomer. Remove it from
the array of monicons and free it.
*/
monicon_old =
g_ptr_array_remove_index (PXM_SEQED_WIDGET (seqed_widget)->moniconGPA, idx);
g_assert (monicon_old != NULL);
polyxmass_monicon_free (monicon_old);
/* At this point we have a fully qualified monicon. Depending on the
value of idx, with respect to the size of the moniconGPA we
either insert the monicon in the sequence array or we append it.
We cannot use the polymer->monomerGPA->len value, because it does
not change, while moniconGPA->len has changed as the effect of
removing the old monicon from it. I was having crashes due using
the polymer->monomerGPA->len value here. Which was wrong of
course.
*/
if (idx == PXM_SEQED_WIDGET (seqed_widget)->moniconGPA->len)
g_ptr_array_add (PXM_SEQED_WIDGET (seqed_widget)->moniconGPA,
monicon_new);
else
g_ptr_array_insert_val (PXM_SEQED_WIDGET (seqed_widget)->moniconGPA,
idx, monicon_new);
return MODIF_CHEM_Y_RENDER_Y;
}
/* It is the responsibility of the caller to set the parameters to
values that she will use to establish if the function was
successful or not.
*/
void
polyxmass_seqed_widget_mnm_modif_modify_monomer_GA (GArray *GA,
gchar *modif,
GtkWidget *seqed_widget,
gchar **errors,
gint *full_success,
gint *full_failure,
gint *chem_failure,
gint *render_failure)
{
gint iter = 0;
gint idx = 0;
GString *gs = NULL;
PxmModifRes res = MODIF_CHEM_N_RENDER_N;
GPtrArray *monomerGPA = NULL;
PxmPolymer *polymer = NULL;
PxmPolchemdefCtxt *polchemdefctxt = NULL;
PxmPolchemdef *polchemdef = NULL;
/* We have a GArray (GA) of indices corresponding to indices in the
polymer sequence where the modification (its name is in modif)
should occur.
*/
g_assert (GA != NULL);
/* If no monomer is to be modified just return 0 since we do not
modify any monomer !
*/
if (GA->len <= 0)
return ;
g_assert (seqed_widget != NULL);
polchemdefctxt = PXM_SEQED_WIDGET (seqed_widget)->polchemdefctxt;
g_assert (polchemdefctxt != NULL);
polchemdef = polchemdefctxt->polchemdef;
g_assert (polchemdef != NULL);
polymer = PXM_SEQED_WIDGET (seqed_widget)->polymer;
g_assert (polymer != NULL);
monomerGPA = polymer->monomerGPA;
g_assert (monomerGPA != NULL);
/* If the polymer sequence is empty, no modif can occur!
*/
if (monomerGPA->len <= 0)
return ;
g_assert (modif != NULL);
g_assert (-1 != pxmchem_modif_get_index_by_name (modif,
polchemdef->modifGPA));
/* If errors is set, we want errors to be a pointer to a NULL gchar
pointer. We will allocate the string ourselves and let the caller
free it after.
*/
if (errors != NULL)
{
g_assert (*errors == NULL);
/* Prepare the GString that will store the errors, but only if
error reporting is asked.
*/
gs = g_string_new ("");
}
/* We now should iterate in the array of indices of the monomers to
be modified and take proper actions each time.
*/
for (iter = 0; iter < GA->len; iter++)
{
idx = g_array_index (GA, gint, iter);
/* Check that we are not going to access a non-existent
monomer... especially if the user edits the polymer sequence
by removing monomers from it.
*/
if (idx > monomerGPA->len)
{
g_critical (_("%s@%d: a position marked to be modified is greater "
"than the size of the polymer! "
"Do not edit the sequence!\n"),
__FILE__, __LINE__);
return ;
}
/* Do the modification work proper.
*/
res = polyxmass_seqed_widget_mnm_modif_modify_monomer (NULL, idx, modif,
seqed_widget);
/* Now, a number of possibilities need to be envisaged, and errors
will have to be logged. Since the first operation is to
make the chemical modification, if it goes wrong the function
returns immediately with MODIF_CHEM_N_RENDER_N.
*/
switch (res)
{
case MODIF_CHEM_Y_RENDER_Y:
if (full_success != NULL)
(*full_success)++;
break;
case MODIF_CHEM_N_RENDER_N:
if (errors)
g_string_append_printf
(gs,
_("pos: '%d' - not modified - no visual\n"),
iter + 1);
if (full_failure != NULL)
(*full_failure)++;
break;
case MODIF_CHEM_Y_RENDER_N:
if (errors)
g_string_append_printf
(gs,
_("pos: '%d' - modified - no visual\n"),
iter + 1);
if (render_failure != NULL)
(*render_failure)++;
break;
case MODIF_CHEM_N_RENDER_Y: /* added for symmetry, for the moment.*/
if (errors)
g_string_append_printf
(gs,
_("pos: '%d' - not modified - visual\n"),
iter + 1);
if (chem_failure != NULL)
(*chem_failure)++;
break;
}
}
/* Now that we have finished doing the work, if the user wanted to
get errors, then we have to give them.
*/
if (errors != NULL)
{
*errors = gs->str;
/* We know we have allocated this GString above, because errors
was not NULL!
*/
g_string_free (gs, FALSE);
}
return;
}
PxmModifRes
polyxmass_seqed_widget_mnm_modif_un_modify_monomer (PxmMonomer *mnm,
gint idx,
gchar *modif,
GtkWidget *seqed_widget)
{
gint res = UN_MODIF_FAILURE;
GdkPixbuf *pixbuf = NULL;
PxmMonomer *monomer = NULL;
PxmPolchemdefCtxt *polchemdefctxt = NULL;
PxmPolchemdef *polchemdef = NULL;
PxmPolymer *polymer = NULL;
PxmMonicon *monicon_old = NULL;
PxmMonicon *monicon_new = NULL;
g_assert (seqed_widget != NULL);
polchemdefctxt = PXM_SEQED_WIDGET (seqed_widget)->polchemdefctxt;
g_assert (polchemdefctxt != NULL);
polchemdef = polchemdefctxt->polchemdef;
g_assert (polchemdef != NULL);
polymer = PXM_SEQED_WIDGET (seqed_widget)->polymer;
g_assert (polymer != NULL);
/* Un-modifying a monomer is a two-step process: first the monomer
must be chemically un-modified (if its current modif is the same
as the modif param, if the latter is non-NULL), and next, if the
un-modification is successful, the graphical rendering must be
performed so that the modification is eliminated from the monicon
of the no-more-modified monomer.
*/
/* Sanity checks pertaining to the size of the polymer sequence.
*/
g_assert (polymer->monomerGPA->len > 0);
g_assert (idx >= 0);
g_assert (idx <= polymer->monomerGPA->len - 1);
/* Make sure we can correctly access the monomer to be un-modified.
*/
if (mnm == NULL)
monomer = g_ptr_array_index (polymer->monomerGPA, idx);
else
{
monomer = mnm ;
/* Sanity check.
*/
g_assert (monomer == g_ptr_array_index (polymer->monomerGPA, idx));
}
g_assert (monomer != NULL);
/* Make sure the modif object is known to the polchemdef, if modif
passed as param is non-NULL.
*/
if (modif != NULL &&
-1 == pxmchem_modif_get_index_by_name (modif, polchemdef->modifGPA))
{
g_critical (_("%s@%d: modif is not known to the polchemdef: '%s'\n"),
__FILE__, __LINE__, modif);
return MODIF_CHEM_N_RENDER_N;
}
/* The call below may return any of these values:
UN_MODIF_SUCCESS, if the unmodification was successful
UN_MODIF_NO_MATCH, if the monomer was modified != 'modif'
UN_MODIF_NO_MODIF, if the monomer was not modified
UN_MODIF_FAILURE, if something went wrong.
*/
res = pxmchem_monomer_un_modify (monomer, modif);
if (res == UN_MODIF_FAILURE)
{
if (modif != NULL)
{
g_critical (_("%s@%d: failed to un-modify monomer "
"at index: '%d' with modif: '%s'\n"),
__FILE__, __LINE__, idx, modif);
}
else
{
g_critical (_("%s@%d: failed to or did not un-modify monomer "
"at index: '%d'\n"),
__FILE__, __LINE__, idx);
}
return MODIF_CHEM_N_RENDER_N;
}
/* The situation is tricky here: we do not want to modify the appearance
of a monomer if its internal chemical state did not change. Which
is why we have to check to return value precisely. In fact,
we only go on with the graphical rendering of the monicon if
res == UN_MODIF_SUCCESS.
*/
if (res != UN_MODIF_SUCCESS)
return MODIF_CHEM_N_RENDER_N;
/* At this point the chemical un-modification went ok, so we can
manage the rendering process. In a prudent way of doing things,
we start by making the new rendered monicon, and if everything
goes well we make the replacement, otherwise we leave the current
monicon in place but issue a critical message.
*/
/* Render a new pixbuf corresponding to the un-modified monomer.
*/
pixbuf = polyxmass_pixbuf_rendering_render_no_modif
(monomer->code,
PXM_SEQED_WIDGET (seqed_widget)->monicon_size,
&(PXM_SEQED_WIDGET (seqed_widget)->pixbufGData),
polchemdefctxt);
if (pixbuf == NULL)
{
g_critical (_("%s@%d: failed to render monicon for un-modified "
"monomer: '%s' at index: '%d'. Chemical un-modification "
"was performed ok, however.\n"),
__FILE__, __LINE__, monomer->code, idx);
return MODIF_CHEM_Y_RENDER_N;
}
/* Now that we have the pixbuf, we can allocate the new monicon so that
a new canvas_item is prepared later.
*/
monicon_new = polyxmass_monicon_new ();
if (FALSE == polyxmass_pixbuf_rendering_monicon_make_canvas_item
(monicon_new,
PXM_SEQED_WIDGET (seqed_widget)->monicon_size,
pixbuf,
idx,
seqed_widget))
{
g_critical (_("%s@%d: failed to make canvas_item for un-modified "
"monomer, code: '%s' at index: '%d'. Chemical "
"un-modification was performed ok, however.\n"),
__FILE__, __LINE__, monomer->code, idx);
return MODIF_CHEM_Y_RENDER_N ;
}
/* At this point, the pixbuf that we got in the first place, with
the call to polyxmass_pixbuf_rendering_render_no_modif() got
referenced by the gnome_canvas_item_new() that makes the canvas
item in the polyxmass_pixbuf_rendering_monicon_make_canvas_item()
call. Thus, when we call the pxm_monicon_free() function on the
monicon, it should just
gtk_object_destroy(GTK_OBJECT(monicon->canvas_item));
which will unref the pixbuf contained in it.
So, the story goes :
1. we get a pixbuf (either pre-existing or allocated anew) with
no reference count incrementing.
2. we construct a canvas_item by using it, which increments its
reference count by 1.
3. we put that pixbuf into a monicon object that will contain it
up to its freeing.
4. some day we free the monicon, which will gtk_object_destroy
the canvas_item, which will decrement the reference count by
1. At this stage we get a reference count identical to the
situation in point 1.
*/
/* Apparently we succeeded in all our attempts, so get the pointer
to the monicon that currently renders the monomer. Remove it from
the array of monicons and free it.
*/
monicon_old =
g_ptr_array_remove_index (PXM_SEQED_WIDGET (seqed_widget)->moniconGPA, idx);
g_assert (monicon_old != NULL);
polyxmass_monicon_free (monicon_old);
/* At this point we have a fully qualified monicon. Depending on the
value of idx, with respect to the size of the moniconGPA we
either insert the monicon in the sequence array or we append it.
We cannot use the polymer->monomerGPA->len value, because it does
not change, while moniconGPA->len has changed as the effect of
removing the old monicon from it. I was having crashes due using
the polymer->monomerGPA->len value here. Which was wrong of
course.
*/
if (idx == PXM_SEQED_WIDGET (seqed_widget)->moniconGPA->len)
g_ptr_array_add (PXM_SEQED_WIDGET (seqed_widget)->moniconGPA,
monicon_new);
else
g_ptr_array_insert_val (PXM_SEQED_WIDGET (seqed_widget)->moniconGPA,
idx, monicon_new);
return MODIF_CHEM_Y_RENDER_Y;
}
void
polyxmass_seqed_widget_mnm_modif_un_modify_monomer_GA (GArray *GA,
gchar *modif,
GtkWidget *seqed_widget,
gchar **errors,
gint *full_success,
gint *full_failure,
gint *chem_failure,
gint *render_failure)
{
gint iter = 0;
gint idx = 0;
GString *gs = NULL;
PxmModifRes res = MODIF_CHEM_N_RENDER_N;
PxmPolymer *polymer = NULL;
PxmPolchemdefCtxt *polchemdefctxt = NULL;
PxmPolchemdef *polchemdef = NULL;
GPtrArray *monomerGPA = NULL;
/* We have a GArray (GA) of indices corresponding to indices in the
polymer sequence where the un-modification should occur. Note
that modif may be NULL, in which case the un-modification will
happen whatever the modification with which the target monomer is
modified. Instead, if modif is non-NULL, the target monomer is
un-modified only if currently modified with a modification of the
same name as the string passed as parameter 'modif'.
*/
g_assert (GA != NULL);
/* If no monomer is to be un-modified just return 0 since we do not
modify any monomer !
*/
if (GA->len <= 0)
return ;
g_assert (seqed_widget != NULL);
polchemdefctxt = PXM_SEQED_WIDGET (seqed_widget)->polchemdefctxt;
g_assert (polchemdefctxt != NULL);
polchemdef = polchemdefctxt->polchemdef;
g_assert (polchemdef != NULL);
polymer = PXM_SEQED_WIDGET (seqed_widget)->polymer;
g_assert (polymer != NULL);
monomerGPA = polymer->monomerGPA;
g_assert (monomerGPA != NULL);
/* If the polymer sequence is empty, no un-modif can occur!
*/
if (monomerGPA->len <= 0)
return ;
/* Sanity check: if modif is non-NULL it must be known to the
polymer type!
*/
if (modif != NULL)
g_assert (-1 != pxmchem_modif_get_index_by_name (modif,
polchemdef->modifGPA));
/* If errors is set, we want errors to be a pointer to a NULL gchar
pointer. We will allocate the string ourselves and let the caller
free it after.
*/
if (errors != NULL)
{
g_assert (*errors == NULL);
/* Prepare the GString that will store the errors, but only if
error reporting is asked.
*/
gs = g_string_new ("");
}
/* We now should iterate in the array of indices of the monomers to
be un-modified and take proper actions each time.
*/
for (iter = 0; iter < GA->len; iter++)
{
idx = g_array_index (GA, gint, iter);
/* Check that we are not going to access a non-existent
monomer... especially if the user edits the polymer sequence
by removing monomers from it.
*/
if (idx > monomerGPA->len)
{
g_critical (_("%s@%d: a position marked to be modified is greater "
"than the size of the polymer! "
"Do not edit the sequence!\n"),
__FILE__, __LINE__);
return ;
}
/* Do the un-modification work proper.
*/
res = polyxmass_seqed_widget_mnm_modif_un_modify_monomer (NULL, idx, modif,
seqed_widget);
/* Now, a number of possibilities need to be envisaged, and errors
will have to be logged. Since the first operation is to
make the chemical modification, if it goes wrong the function
returns immediately with MODIF_CHEM_N_RENDER_N.
*/
switch (res)
{
case MODIF_CHEM_Y_RENDER_Y:
if (full_success != NULL)
(*full_success)++;
break;
case MODIF_CHEM_N_RENDER_N:
if (errors)
g_string_append_printf
(gs,
_("pos: '%d' - not un-modified - no visual\n"),
iter + 1);
if (full_failure != NULL)
(*full_failure)++;
break;
case MODIF_CHEM_Y_RENDER_N:
if (errors)
g_string_append_printf
(gs,
_("pos: '%d' - un-modified - no visual\n"),
iter + 1);
if (render_failure != NULL)
(*render_failure)++;
break;
case MODIF_CHEM_N_RENDER_Y: /* added for symmetry, for the moment.*/
if (errors)
g_string_append_printf
(gs,
_("pos: '%d' - not un-modified - visual\n"),
iter + 1);
if (chem_failure != NULL)
(*chem_failure)++;
break;
}
}
/* Now that we have finished doing the work, if the user wanted to
get errors, then we have to give them.
*/
if (errors != NULL)
{
*errors = gs->str;
/* We know we have allocated this GString above, because errors
was not NULL!
*/
g_string_free (gs, FALSE);
}
return;
}
/* WINDOW LIFE-CYCLE FUNCTIONS.
*/
void
polyxmass_seqed_widget_mnm_modif_wnd_really_close (GtkWidget *window)
{
gint count = 0;
g_assert (window != NULL);
/*
Prior to closing the window, we want to make sure that no
pending timed-out messages are there...
*/
count = polyxmass_timeoutmsg_messages_remove ((GtkWindow *) window);
gtk_widget_destroy (window);
}
gboolean
polyxmass_seqed_widget_mnm_modif_wnd_delete_event (GtkWidget *window,
GdkEventAny *event,
gpointer data)
{
GtkWidget *seqed_widget = data;
gchar *help = NULL;
g_assert (window != NULL);
g_assert (seqed_widget != NULL);
help = g_strdup_printf ("monomer_modif_wnd-%p", window);
/* We set the datum to NULL, then the GDestroyNotify callback that
was specified when the datum was set first (that is
xxx_wnd_really_close () function above) will be called, thus
destroying *this window, which is exactly what we want !
*/
g_object_set_data (G_OBJECT (seqed_widget),
help, NULL);
g_free (help);
return TRUE;
}
gboolean
polyxmass_seqed_widget_mnm_modif_wnd_destroy_event (GtkWidget *window,
GdkEventAny *event,
gpointer data)
{
return FALSE;
}
|