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
|
/*=========================================================================
Program: ParaView
Module: vtkSMSessionProxyManager.cxx
Copyright (c) Kitware, Inc.
All rights reserved.
See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkSMSessionProxyManager.h"
#include "vtkCollection.h"
#include "vtkDebugLeaks.h"
#include "vtkEventForwarderCommand.h"
#include "vtkNew.h"
#include "vtkObjectFactory.h"
#include "vtkProcessModule.h"
#include "vtkPVConfig.h" // for PARAVIEW_VERSION_*
#include "vtkPVInstantiator.h"
#include "vtkPVProxyDefinitionIterator.h"
#include "vtkPVXMLElement.h"
#include "vtkPVXMLParser.h"
#include "vtkReservedRemoteObjectIds.h"
#include "vtkSmartPointer.h"
#include "vtkSMCollaborationManager.h"
#include "vtkSMCoreUtilities.h"
#include "vtkSMDeserializerProtobuf.h"
#include "vtkSMDocumentation.h"
#include "vtkSMGlobalPropertiesLinkUndoElement.h"
#include "vtkSMPipelineState.h"
#include "vtkSMPropertyIterator.h"
#include "vtkSMProxyDefinitionManager.h"
#include "vtkSMProxy.h"
#include "vtkSMProxyIterator.h"
#include "vtkSMProxyLocator.h"
#include "vtkSMProxyManager.h"
#include "vtkSMProxyProperty.h"
#include "vtkSMProxySelectionModel.h"
#include "vtkSMSessionClient.h"
#include "vtkSMStateLoader.h"
#include "vtkSMStateLocator.h"
#include "vtkSMUndoStackBuilder.h"
#include "vtkSMUndoStack.h"
#include "vtkStdString.h"
#include "vtkStringList.h"
#include "vtkVersion.h"
#include <map>
#include <set>
#include <vector>
#include <sstream>
#include <vtksys/RegularExpression.hxx>
#include <assert.h>
#include "vtkSMSessionProxyManagerInternals.h"
#if 0 // for debugging
class vtkSMProxyRegObserver : public vtkCommand
{
public:
virtual void Execute(vtkObject*, unsigned long event, void* data)
{
vtkSMProxyManager::RegisteredProxyInformation* info =
(vtkSMProxyManager::RegisteredProxyInformation*)data;
cout << info->Proxy
<< " " << vtkCommand::GetStringFromEventId(event)
<< " " << info->GroupName
<< " " << info->ProxyName
<< endl;
}
};
#endif
class vtkSMProxyManagerProxySet : public std::set<vtkSMProxy*> {};
//*****************************************************************************
class vtkSMProxyManagerObserver : public vtkCommand
{
public:
static vtkSMProxyManagerObserver* New()
{ return new vtkSMProxyManagerObserver(); }
void SetTarget(vtkSMSessionProxyManager* t)
{
this->Target = t;
}
virtual void Execute(vtkObject *obj, unsigned long event, void* data)
{
if (this->Target)
{
this->Target->ExecuteEvent(obj, event, data);
}
}
protected:
vtkSMProxyManagerObserver()
{
this->Target = 0;
}
vtkSMSessionProxyManager* Target;
};
//*****************************************************************************
class vtkSMProxyManagerForwarder : public vtkCommand
{
public:
static vtkSMProxyManagerForwarder* New()
{ return new vtkSMProxyManagerForwarder(); }
virtual void Execute(vtkObject*, unsigned long event, void* data)
{
if (vtkSMProxyManager::IsInitialized())
{
vtkSMProxyManager::GetProxyManager()->InvokeEvent(event, data);
}
}
protected:
vtkSMProxyManagerForwarder()
{
}
};
//*****************************************************************************
//---------------------------------------------------------------------------
vtkSMSessionProxyManager* vtkSMSessionProxyManager::New(vtkSMSession* session)
{
#ifdef VTK_DEBUG_LEAKS
vtkDebugLeaks::ConstructClass("vtkSMSessionProxyManager");
#endif
return new vtkSMSessionProxyManager(session);
}
//---------------------------------------------------------------------------
vtkSMSessionProxyManager::vtkSMSessionProxyManager(vtkSMSession* session)
{
this->Superclass::SetSession(session);
this->StateUpdateNotification = true;
this->UpdateInputProxies = 0;
this->Internals = new vtkSMSessionProxyManagerInternals;
this->Internals->ProxyManager = this;
this->Observer = vtkSMProxyManagerObserver::New();
this->Observer->SetTarget(this);
#if 0 // for debugging
vtkSMProxyRegObserver* obs = new vtkSMProxyRegObserver;
this->AddObserver(vtkCommand::RegisterEvent, obs);
this->AddObserver(vtkCommand::UnRegisterEvent, obs);
#endif
this->ProxyDefinitionManager = vtkSMProxyDefinitionManager::New();
this->ProxyDefinitionManager->AddObserver(
vtkCommand::RegisterEvent, this->Observer);
this->ProxyDefinitionManager->AddObserver(
vtkCommand::UnRegisterEvent, this->Observer);
this->ProxyDefinitionManager->AddObserver(
vtkSMProxyDefinitionManager::ProxyDefinitionsUpdated, this->Observer);
this->ProxyDefinitionManager->AddObserver(
vtkSMProxyDefinitionManager::CompoundProxyDefinitionsUpdated, this->Observer);
this->ProxyDefinitionManager->SetSession(session);
this->PipelineState = vtkSMPipelineState::New();
this->PipelineState->SetSession(this->Session);
// setup event forwarder so that it forwards all events fired by this class via
// the global proxy manager.
vtkNew<vtkSMProxyManagerForwarder> forwarder;
this->AddObserver(vtkCommand::AnyEvent, forwarder.GetPointer());
}
//---------------------------------------------------------------------------
vtkSMSessionProxyManager::~vtkSMSessionProxyManager()
{
// This is causing a PushState() when the object is being destroyed. This
// causes errors since the ProxyManager is destroyed only when the session is
// being deleted, thus the session cannot be valid at this point.
//this->UnRegisterProxies();
delete this->Internals;
this->Observer->SetTarget(0);
this->Observer->Delete();
this->ProxyDefinitionManager->Delete();
this->ProxyDefinitionManager = NULL;
this->PipelineState->Delete();
this->PipelineState = NULL;
}
//----------------------------------------------------------------------------
vtkTypeUInt32 vtkSMSessionProxyManager::GetReservedGlobalID()
{
return vtkReservedRemoteObjectIds::RESERVED_PROXY_MANAGER_ID;
}
//----------------------------------------------------------------------------
void vtkSMSessionProxyManager::InstantiateGroupPrototypes(const char* groupName)
{
if (!groupName)
{
return;
}
assert(this->ProxyDefinitionManager != 0);
std::ostringstream newgroupname;
newgroupname << groupName << "_prototypes" << ends;
// Not a huge fan of this iterator API. Need to make it more consistent with
// VTK.
vtkPVProxyDefinitionIterator* iter =
this->ProxyDefinitionManager->NewSingleGroupIterator(groupName);
// Find the XML elements from which the proxies can be instantiated and
// initialized
for ( iter->InitTraversal(); !iter->IsDoneWithTraversal();
iter->GoToNextItem())
{
const char* xml_name = iter->GetProxyName();
if (this->GetProxy(newgroupname.str().c_str(), xml_name) == NULL)
{
vtkSMProxy* proxy = this->NewProxy(groupName, xml_name);
if (proxy)
{
proxy->SetSession(NULL);
proxy->SetLocation(0);
proxy->SetPrototype(true);
this->RegisterProxy(newgroupname.str().c_str(), xml_name, proxy);
proxy->FastDelete();
}
}
}
iter->Delete();
}
//----------------------------------------------------------------------------
void vtkSMSessionProxyManager::InstantiatePrototypes()
{
assert(this->ProxyDefinitionManager != 0);
vtkPVProxyDefinitionIterator* iter =
this->ProxyDefinitionManager->NewIterator();
for (iter->InitTraversal(); !iter->IsDoneWithTraversal();
iter->GoToNextGroup())
{
this->InstantiateGroupPrototypes(iter->GetGroupName());
}
}
//----------------------------------------------------------------------------
vtkSMProxy* vtkSMSessionProxyManager::NewProxy(
const char* groupName, const char* proxyName, const char* subProxyName)
{
if (!groupName || !proxyName)
{
return 0;
}
// Find the XML element from which the proxy can be instantiated and
// initialized
vtkPVXMLElement* element = this->GetProxyElement( groupName, proxyName,
subProxyName);
if (element)
{
return this->NewProxy(element, groupName, proxyName, subProxyName);
}
return 0;
}
//---------------------------------------------------------------------------
vtkSMProxy* vtkSMSessionProxyManager::NewProxy(vtkPVXMLElement* pelement,
const char* groupname,
const char* proxyname,
const char* subProxyName)
{
vtkObject* object = 0;
std::ostringstream cname;
cname << "vtkSM" << pelement->GetName() << ends;
object = vtkPVInstantiator::CreateInstance(cname.str().c_str());
vtkSMProxy* proxy = vtkSMProxy::SafeDownCast(object);
if (proxy)
{
// XMLName/XMLGroup should be set before ReadXMLAttributes so sub proxy
// can be found based on their names when sent to the PM Side
proxy->SetXMLGroup(groupname);
proxy->SetXMLName(proxyname);
proxy->SetXMLSubProxyName(subProxyName);
proxy->SetSession(this->GetSession());
proxy->ReadXMLAttributes(this, pelement);
}
else
{
vtkWarningMacro("Creation of new proxy " << cname.str() << " failed ("
<< groupname << ", " << proxyname << ").");
}
return proxy;
}
//---------------------------------------------------------------------------
vtkSMDocumentation* vtkSMSessionProxyManager::GetProxyDocumentation(
const char* groupName, const char* proxyName)
{
if (!groupName || !proxyName)
{
return 0;
}
vtkSMProxy* proxy = this->GetPrototypeProxy(groupName, proxyName);
return proxy? proxy->GetDocumentation() : NULL;
}
//---------------------------------------------------------------------------
vtkSMDocumentation* vtkSMSessionProxyManager::GetPropertyDocumentation(
const char* groupName, const char* proxyName, const char* propertyName)
{
if (!groupName || !proxyName || !propertyName)
{
return 0;
}
vtkSMProxy* proxy = this->GetPrototypeProxy(groupName, proxyName);
if (proxy)
{
vtkSMProperty* prop = proxy->GetProperty(propertyName);
if (prop)
{
return prop->GetDocumentation();
}
}
return 0;
}
//---------------------------------------------------------------------------
vtkPVXMLElement* vtkSMSessionProxyManager::GetProxyElement(const char* groupName,
const char* proxyName,
const char* subProxyName)
{
assert(this->ProxyDefinitionManager != 0);
return this->ProxyDefinitionManager->GetCollapsedProxyDefinition( groupName,
proxyName,
subProxyName,
true);
}
//---------------------------------------------------------------------------
unsigned int vtkSMSessionProxyManager::GetNumberOfProxies(const char* group)
{
vtkSMSessionProxyManagerInternals::ProxyGroupType::iterator it =
this->Internals->RegisteredProxyMap.find(group);
if ( it != this->Internals->RegisteredProxyMap.end() )
{
size_t size = 0;
vtkSMProxyManagerProxyMapType::iterator it2 =
it->second.begin();
for (; it2 != it->second.end(); ++it2)
{
size += it2->second.size();
}
return static_cast<unsigned int>(size);
}
return 0;
}
//---------------------------------------------------------------------------
// No errors are raised if a proxy definition for the requested proxy is not
// found.
vtkSMProxy* vtkSMSessionProxyManager::GetPrototypeProxy(const char* groupname,
const char* name)
{
if (!this->ProxyDefinitionManager)
{
return NULL;
}
std::string protype_group = groupname;
protype_group += "_prototypes";
vtkSMProxy* proxy = this->GetProxy(protype_group.c_str(), name);
if (proxy)
{
return proxy;
}
// silently ask for the definition. If not found return NULL.
vtkPVXMLElement* xmlElement =
this->ProxyDefinitionManager->GetCollapsedProxyDefinition(
groupname, name, NULL, false);
if (xmlElement == NULL)
{
// No definition was located for the requested proxy.
// Cannot create the prototype.
return 0;
}
proxy = this->NewProxy(groupname, name);
if (!proxy)
{
return 0;
}
proxy->SetLocation(0);
proxy->SetPrototype(true);
// register the proxy as a prototype.
this->RegisterProxy(protype_group.c_str(), name, proxy);
proxy->Delete();
return proxy;
}
//---------------------------------------------------------------------------
void vtkSMSessionProxyManager::RemovePrototype(
const char* groupname, const char* proxyname)
{
std::string prototype_group = groupname;
prototype_group += "_prototypes";
vtkSMProxy* proxy = this->GetProxy(prototype_group.c_str(), proxyname);
if (proxy)
{
// prototype exists, so remove it.
this->UnRegisterProxy(prototype_group.c_str(), proxyname, proxy);
}
}
//---------------------------------------------------------------------------
vtkSMProxy* vtkSMSessionProxyManager::GetProxy(const char* group, const char* name)
{
vtkSMSessionProxyManagerInternals::ProxyGroupType::iterator it =
this->Internals->RegisteredProxyMap.find(group);
if ( it != this->Internals->RegisteredProxyMap.end() )
{
vtkSMProxyManagerProxyMapType::iterator it2 =
it->second.find(name);
if (it2 != it->second.end())
{
if (it2->second.begin() != it2->second.end())
{
return it2->second.front()->Proxy.GetPointer();
}
}
}
return 0;
}
//---------------------------------------------------------------------------
vtkSMProxy* vtkSMSessionProxyManager::GetProxy(const char* name)
{
vtkSMSessionProxyManagerInternals::ProxyGroupType::iterator it =
this->Internals->RegisteredProxyMap.begin();
for (; it != this->Internals->RegisteredProxyMap.end(); it++)
{
vtkSMProxyManagerProxyMapType::iterator it2 =
it->second.find(name);
if (it2 != it->second.end())
{
if (it2->second.begin() != it2->second.end())
{
return it2->second.front()->Proxy.GetPointer();
}
}
}
return 0;
}
//---------------------------------------------------------------------------
void vtkSMSessionProxyManager::GetProxies(const char* group,
const char* name, vtkCollection* collection)
{
collection->RemoveAllItems();
vtkSMSessionProxyManagerInternals::ProxyGroupType::iterator it =
this->Internals->RegisteredProxyMap.find(group);
if(it != this->Internals->RegisteredProxyMap.end())
{
if(name == NULL)
{
vtkSMProxyManagerProxyMapType::iterator it2 =
it->second.begin();
std::set<vtkTypeUInt32> ids;
for (; it2 != it->second.end(); it2++)
{
vtkSMProxyManagerProxyListType::iterator it3 = it2->second.begin();
for (; it3 != it2->second.end(); ++it3)
{
if(ids.find(it3->GetPointer()->Proxy->GetGlobalID()) == ids.end())
{
ids.insert(it3->GetPointer()->Proxy->GetGlobalID());
collection->AddItem(it3->GetPointer()->Proxy);
}
}
}
}
else
{
vtkSMProxyManagerProxyMapType::iterator it2 = it->second.find(name);
if (it2 != it->second.end())
{
vtkSMProxyManagerProxyListType::iterator it3 = it2->second.begin();
for (; it3 != it2->second.end(); ++it3)
{
collection->AddItem(it3->GetPointer()->Proxy);
}
}
}
}
}
//---------------------------------------------------------------------------
void vtkSMSessionProxyManager::GetProxyNames(const char* groupname,
vtkSMProxy* proxy, vtkStringList* names)
{
if (!names)
{
return;
}
names->RemoveAllItems();
if (!groupname || !proxy)
{
return;
}
vtkSMSessionProxyManagerInternals::ProxyGroupType::iterator it =
this->Internals->RegisteredProxyMap.find(groupname);
if ( it != this->Internals->RegisteredProxyMap.end() )
{
vtkSMProxyManagerProxyMapType::iterator it2 =
it->second.begin();
for (; it2 != it->second.end(); it2++)
{
if (it2->second.Contains(proxy))
{
names->AddString(it2->first.c_str());
}
}
}
}
//---------------------------------------------------------------------------
vtkStdString vtkSMSessionProxyManager::RegisterProxy(const char* groupname, vtkSMProxy* proxy)
{
assert(proxy != NULL);
vtkStdString label = vtkSMCoreUtilities::SanitizeName(proxy->GetXMLLabel());
vtkStdString name = this->GetUniqueProxyName(groupname, label.c_str());
this->RegisterProxy(groupname, name.c_str(), proxy);
return groupname;
}
//---------------------------------------------------------------------------
vtkStdString vtkSMSessionProxyManager::GetUniqueProxyName(
const char* groupname, const char* prefix)
{
if (!groupname || !prefix)
{
return vtkStdString();
}
vtkSMSessionProxyManagerInternals::ProxyGroupType::iterator it =
this->Internals->RegisteredProxyMap.find(groupname);
if (it == this->Internals->RegisteredProxyMap.end())
{
int suffix = 1;
std::ostringstream name_stream;
name_stream << prefix << suffix;
return name_stream.str();
}
std::set<std::string> existingNames;
for (vtkSMProxyManagerProxyMapType::iterator it2 = it->second.begin();
it2 != it->second.end(); it2++)
{
existingNames.insert(it2->first);
}
for (int suffix=1; suffix < VTK_INT_MAX; ++suffix)
{
std::ostringstream name_stream;
name_stream << prefix << suffix;
if (existingNames.find(name_stream.str()) == existingNames.end())
{
return name_stream.str();
}
}
vtkErrorMacro("Failed to come up with a unique name!");
abort();
return vtkStdString(prefix);
}
//---------------------------------------------------------------------------
const char* vtkSMSessionProxyManager::GetProxyName(const char* groupname,
vtkSMProxy* proxy)
{
if (!groupname || !proxy)
{
return 0;
}
vtkSMSessionProxyManagerInternals::ProxyGroupType::iterator it =
this->Internals->RegisteredProxyMap.find(groupname);
if ( it != this->Internals->RegisteredProxyMap.end() )
{
vtkSMProxyManagerProxyMapType::iterator it2 =
it->second.begin();
for (; it2 != it->second.end(); it2++)
{
if (it2->second.Contains(proxy))
{
return it2->first.c_str();
}
}
}
return 0;
}
//---------------------------------------------------------------------------
const char* vtkSMSessionProxyManager::GetProxyName(const char* groupname,
unsigned int idx)
{
if (!groupname)
{
return 0;
}
unsigned int counter=0;
vtkSMSessionProxyManagerInternals::ProxyGroupType::iterator it =
this->Internals->RegisteredProxyMap.find(groupname);
if ( it != this->Internals->RegisteredProxyMap.end() )
{
vtkSMProxyManagerProxyMapType::iterator it2 =
it->second.begin();
for (; it2 != it->second.end(); it2++)
{
if (counter == idx)
{
return it2->first.c_str();
}
counter++;
}
}
return 0;
}
//---------------------------------------------------------------------------
const char* vtkSMSessionProxyManager::IsProxyInGroup(vtkSMProxy* proxy,
const char* groupname)
{
if (!proxy || !groupname)
{
return 0;
}
vtkSMSessionProxyManagerInternals::ProxyGroupType::iterator it =
this->Internals->RegisteredProxyMap.find(groupname);
if ( it != this->Internals->RegisteredProxyMap.end() )
{
vtkSMProxyManagerProxyMapType::iterator it2 =
it->second.begin();
for (; it2 != it->second.end(); it2++)
{
if (it2->second.Contains(proxy))
{
return it2->first.c_str();
}
}
}
return 0;
}
namespace
{
struct vtkSMProxyManagerProxyInformation
{
std::string GroupName;
std::string ProxyName;
vtkSMProxy* Proxy;
};
}
//---------------------------------------------------------------------------
void vtkSMSessionProxyManager::UnRegisterProxies()
{
// Clear internal proxy containers
std::vector<vtkSMProxyManagerProxyInformation> toUnRegister;
vtkSMProxyIterator* iter = vtkSMProxyIterator::New();
iter->SetModeToAll();
iter->SetSessionProxyManager(this);
for (iter->Begin(); !iter->IsAtEnd(); iter->Next())
{
vtkSMProxyManagerProxyInformation info;
info.GroupName = iter->GetGroup();
info.ProxyName = iter->GetKey();
info.Proxy = iter->GetProxy();
toUnRegister.push_back(info);
}
iter->Delete();
std::vector<vtkSMProxyManagerProxyInformation>::iterator vIter =
toUnRegister.begin();
for (;vIter != toUnRegister.end(); ++vIter)
{
this->UnRegisterProxy(vIter->GroupName.c_str(), vIter->ProxyName.c_str(),
vIter->Proxy);
}
this->Internals->ModifiedProxies.clear();
this->Internals->RegisteredProxyTuple.clear();
this->Internals->State.ClearExtension(PXMRegistrationState::registered_proxy);
// Push state for undo/redo BUT only if it is not a clean up before deletion.
if(this->PipelineState->GetSession())
{
this->TriggerStateUpdate();
}
}
//---------------------------------------------------------------------------
void vtkSMSessionProxyManager::UnRegisterProxy( const char* group, const char* name,
vtkSMProxy* proxy)
{
if (!group || !name)
{
return;
}
// Just in case a proxy ref is NOT held outside the ProxyManager iteself
// Keep one during the full method call so the event could still have a valid
// proxy object.
vtkSmartPointer<vtkSMProxy> proxyHolder = proxy;
std::string nameHolder(name);
std::string groupHolder(group);
// Do something only if the given tuple was found
if(this->Internals->RemoveTuples(group, name, proxy))
{
vtkSMProxyManager::RegisteredProxyInformation info;
info.Proxy = proxy;
info.GroupName = groupHolder.c_str();
info.ProxyName = nameHolder.c_str();
info.Type = vtkSMProxyManager::RegisteredProxyInformation::PROXY;
this->InvokeEvent(vtkCommand::UnRegisterEvent, &info);
this->UnMarkProxyAsModified(info.Proxy);
// Push state for undo/redo
this->TriggerStateUpdate();
}
}
//---------------------------------------------------------------------------
void vtkSMSessionProxyManager::UnRegisterProxy(const char* name)
{
// Remove entries and keep them in a set
std::set<vtkSMProxyManagerEntry> entriesToRemove;
this->Internals->RemoveTuples(name, entriesToRemove);
// Notify that some entries have been deleted
std::set<vtkSMProxyManagerEntry>::iterator iter = entriesToRemove.begin();
while(iter != entriesToRemove.end())
{
vtkSMProxyManager::RegisteredProxyInformation info;
info.Proxy = iter->Proxy;
info.GroupName = iter->Group.c_str();
info.ProxyName = iter->Name.c_str();
info.Type = vtkSMProxyManager::RegisteredProxyInformation::PROXY;
this->InvokeEvent(vtkCommand::UnRegisterEvent, &info);
this->UnMarkProxyAsModified(info.Proxy);
// Move forward
iter++;
}
// Push new state only if changed occured
if(entriesToRemove.size() > 0)
{
this->TriggerStateUpdate();
}
}
//---------------------------------------------------------------------------
void vtkSMSessionProxyManager::UnRegisterProxy(vtkSMProxy* proxy)
{
// Find tuples
std::set<vtkSMProxyManagerEntry> tuplesToRemove;
this->Internals->FindProxyTuples(proxy, tuplesToRemove);
// Remove tuples
std::set<vtkSMProxyManagerEntry>::iterator iter = tuplesToRemove.begin();
while(iter != tuplesToRemove.end())
{
this->UnRegisterProxy(iter->Group.c_str(), iter->Name.c_str(), iter->Proxy);
iter++;
}
// Push new state only if changed occured
if(tuplesToRemove.size() > 0)
{
this->TriggerStateUpdate();
}
}
//---------------------------------------------------------------------------
void vtkSMSessionProxyManager::RegisterProxy(const char* groupname,
const char* name,
vtkSMProxy* proxy)
{
if (!proxy)
{
return;
}
if (groupname == NULL)
{
vtkErrorMacro("'groupname' cannot be NULL.");
return;
}
if (name == NULL || name[0] == 0)
{
// come up with a new name and register the proxy.
this->RegisterProxy(groupname, proxy);
return;
}
vtkSMProxyManagerProxyListType &proxy_list =
this->Internals->RegisteredProxyMap[groupname][name];
if (proxy_list.Contains(proxy))
{
return;
}
// Add Tuple
this->Internals->RegisteredProxyTuple.insert(
vtkSMProxyManagerEntry( groupname, name, proxy ));
vtkSMProxyManagerProxyInfo* proxyInfo = vtkSMProxyManagerProxyInfo::New();
proxy_list.push_back(proxyInfo);
proxyInfo->FastDelete();
proxyInfo->Proxy = proxy;
// Add observers to note proxy modification.
proxyInfo->ModifiedObserverTag = proxy->AddObserver(
vtkCommand::PropertyModifiedEvent, this->Observer);
proxyInfo->StateChangedObserverTag = proxy->AddObserver(
vtkCommand::StateChangedEvent, this->Observer);
proxyInfo->UpdateObserverTag = proxy->AddObserver(vtkCommand::UpdateEvent,
this->Observer);
proxyInfo->UpdateInformationObserverTag = proxy->AddObserver(
vtkCommand::UpdateInformationEvent, this->Observer);
// Note, these observer will be removed in the destructor of proxyInfo.
// Update state
if(proxy->GetLocation() != 0 && !proxy->IsPrototype()) // Not a prototype !!!
{
proxy->CreateVTKObjects(); // Make sure an ID has been assigned to it
// Do not put prototype groups in state
vtksys::RegularExpression prototypesRe("_prototypes$");
if (!prototypesRe.find(groupname))
{
PXMRegistrationState_Entry *entry =
this->Internals->State.AddExtension(PXMRegistrationState::registered_proxy);
entry->set_group(groupname);
entry->set_name(name);
entry->set_global_id(proxy->GetGlobalID());
// Push state for undo/redo
this->TriggerStateUpdate();
}
}
// Fire event.
vtkSMProxyManager::RegisteredProxyInformation info;
info.Proxy = proxy;
info.GroupName = groupname;
info.ProxyName = name;
info.Type = vtkSMProxyManager::RegisteredProxyInformation::PROXY;
this->InvokeEvent(vtkCommand::RegisterEvent, &info);
}
//---------------------------------------------------------------------------
void vtkSMSessionProxyManager::UpdateRegisteredProxies(const char* groupname,
int modified_only /*=1*/)
{
vtkSMSessionProxyManagerInternals::ProxyGroupType::iterator it =
this->Internals->RegisteredProxyMap.find(groupname);
if ( it != this->Internals->RegisteredProxyMap.end() )
{
vtkSMProxyManagerProxyMapType::iterator it2 = it->second.begin();
for (; it2 != it->second.end(); it2++)
{
vtkSMProxyManagerProxyListType::iterator it3 = it2->second.begin();
for (; it3 != it2->second.end(); ++it3)
{
// Check is proxy is in the modified set.
if (!modified_only ||
this->Internals->ModifiedProxies.find(it3->GetPointer()->Proxy.GetPointer())
!= this->Internals->ModifiedProxies.end())
{
it3->GetPointer()->Proxy.GetPointer()->UpdateVTKObjects();
it3->GetPointer()->Proxy.GetPointer()->UpdatePipelineInformation();
}
}
}
}
}
//---------------------------------------------------------------------------
void vtkSMSessionProxyManager::UpdateRegisteredProxies(int modified_only /*=1*/)
{
vtksys::RegularExpression prototypesRe("_prototypes$");
vtkSMSessionProxyManagerInternals::ProxyGroupType::iterator it =
this->Internals->RegisteredProxyMap.begin();
for (; it != this->Internals->RegisteredProxyMap.end(); it++)
{
if (prototypesRe.find(it->first))
{
// skip the prototypes.
continue;
}
vtkSMProxyManagerProxyMapType::iterator it2 = it->second.begin();
for (; it2 != it->second.end(); it2++)
{
// Check is proxy is in the modified set.
vtkSMProxyManagerProxyListType::iterator it3 = it2->second.begin();
for (; it3 != it2->second.end(); ++it3)
{
// Check if proxy is in the modified set.
if (!modified_only ||
this->Internals->ModifiedProxies.find(it3->GetPointer()->Proxy.GetPointer())
!= this->Internals->ModifiedProxies.end())
{
it3->GetPointer()->Proxy.GetPointer()->UpdateVTKObjects();
it3->GetPointer()->Proxy.GetPointer()->UpdatePipelineInformation();
}
}
}
}
}
//---------------------------------------------------------------------------
void vtkSMSessionProxyManager::UpdateRegisteredProxiesInOrder(int modified_only/*=1*/)
{
this->UpdateInputProxies = 1;
this->UpdateRegisteredProxies(modified_only);
this->UpdateInputProxies = 0;
}
//---------------------------------------------------------------------------
void vtkSMSessionProxyManager::UpdateProxyInOrder(vtkSMProxy* proxy)
{
this->UpdateInputProxies = 1;
proxy->UpdateVTKObjects();
this->UpdateInputProxies = 0;
}
//---------------------------------------------------------------------------
int vtkSMSessionProxyManager::GetNumberOfLinks()
{
return static_cast<int>(this->Internals->RegisteredLinkMap.size());
}
//---------------------------------------------------------------------------
const char* vtkSMSessionProxyManager::GetLinkName(int idx)
{
int numlinks = this->GetNumberOfLinks();
if(idx >= numlinks)
{
return NULL;
}
vtkSMSessionProxyManagerInternals::LinkType::iterator it =
this->Internals->RegisteredLinkMap.begin();
for(int i=0; i<idx; i++)
{
it++;
}
return it->first.c_str();
}
//---------------------------------------------------------------------------
void vtkSMSessionProxyManager::RegisterLink(const char* name, vtkSMLink* link)
{
vtkSMSessionProxyManagerInternals::LinkType::iterator it =
this->Internals->RegisteredLinkMap.find(name);
if (it != this->Internals->RegisteredLinkMap.end())
{
vtkWarningMacro("Replacing previously registered link with name " << name);
}
this->Internals->RegisteredLinkMap[name] = link;
// PXM state management
link->SetSession(this->GetSession());
link->PushStateToSession();
this->Internals->UpdateLinkState();
this->TriggerStateUpdate();
vtkSMProxyManager::RegisteredProxyInformation info;
info.Proxy = 0;
info.GroupName = 0;
info.ProxyName = name;
info.Type = vtkSMProxyManager::RegisteredProxyInformation::LINK;
this->InvokeEvent(vtkCommand::RegisterEvent, &info);
}
//---------------------------------------------------------------------------
vtkSMLink* vtkSMSessionProxyManager::GetRegisteredLink(const char* name)
{
vtkSMSessionProxyManagerInternals::LinkType::iterator it =
this->Internals->RegisteredLinkMap.find(name);
if (it != this->Internals->RegisteredLinkMap.end())
{
return it->second.GetPointer();
}
return NULL;
}
//---------------------------------------------------------------------------
void vtkSMSessionProxyManager::UnRegisterLink(const char* name)
{
std::string nameHolder = (name? name : "");
vtkSMSessionProxyManagerInternals::LinkType::iterator it =
this->Internals->RegisteredLinkMap.find(name);
if (it != this->Internals->RegisteredLinkMap.end())
{
this->Internals->RegisteredLinkMap.erase(it);
// PXM state management
this->Internals->UpdateLinkState();
this->TriggerStateUpdate();
vtkSMProxyManager::RegisteredProxyInformation info;
info.Proxy = 0;
info.GroupName = 0;
info.ProxyName = nameHolder.c_str();
info.Type = vtkSMProxyManager::RegisteredProxyInformation::LINK;
this->InvokeEvent(vtkCommand::UnRegisterEvent, &info);
}
}
//---------------------------------------------------------------------------
void vtkSMSessionProxyManager::UnRegisterAllLinks()
{
this->Internals->RegisteredLinkMap.clear();
// PXM state management
this->Internals->UpdateLinkState();
this->TriggerStateUpdate();
}
//---------------------------------------------------------------------------
void vtkSMSessionProxyManager::ExecuteEvent(vtkObject* obj, unsigned long event,
void* data)
{
// Check source object
vtkSMProxy* proxy = vtkSMProxy::SafeDownCast(obj);
// Manage ProxyDefinitionManager Events
if(obj == this->ProxyDefinitionManager)
{
vtkSIProxyDefinitionManager::RegisteredDefinitionInformation* defInfo;
switch(event)
{
case vtkCommand::RegisterEvent:
case vtkCommand::UnRegisterEvent:
defInfo = reinterpret_cast<
vtkSIProxyDefinitionManager::RegisteredDefinitionInformation*>(data);
if(defInfo->CustomDefinition)
{
vtkSMProxyManager::RegisteredProxyInformation info;
info.Proxy = 0;
info.GroupName = defInfo->GroupName;
info.ProxyName = defInfo->ProxyName;
info.Type = vtkSMProxyManager::RegisteredProxyInformation::COMPOUND_PROXY_DEFINITION;
this->InvokeEvent(event, &info);
}
// Both these events imply that the definition may have somehow
// changed. If so, we need to ensure that any old prototypes we have
// for this proxy type are removed, otherwise we may end up using
// obsolete prototypes.
this->RemovePrototype(defInfo->GroupName, defInfo->ProxyName);
break;
default:
this->InvokeEvent(event, data);
break;
}
}
// Manage proxy modification call back to mark proxy dirty...
else if (proxy)
{
switch (event)
{
case vtkCommand::PropertyModifiedEvent:
{
// Some property on the proxy has been modified.
this->MarkProxyAsModified(proxy);
vtkSMProxyManager::ModifiedPropertyInformation info;
info.Proxy = proxy;
info.PropertyName = reinterpret_cast<const char*>(data);
if (info.PropertyName)
{
this->InvokeEvent(vtkCommand::PropertyModifiedEvent,
&info);
}
}
break;
case vtkCommand::StateChangedEvent:
{
// I wonder if I need to mark the proxy modified. Cause when state
// changes, the properties are pushed as well so ideally we should call
// MarkProxyAsModified() and then UnMarkProxyAsModified() :).
// this->MarkProxyAsModified(proxy);
vtkSMProxyManager::StateChangedInformation info;
info.Proxy = proxy;
info.StateChangeElement = reinterpret_cast<vtkPVXMLElement*>(data);
if (info.StateChangeElement)
{
this->InvokeEvent(vtkCommand::StateChangedEvent, &info);
}
}
break;
case vtkCommand::UpdateInformationEvent:
this->InvokeEvent(vtkCommand::UpdateInformationEvent, proxy);
break;
case vtkCommand::UpdateEvent:
// Proxy has been updated.
this->UnMarkProxyAsModified(proxy);
break;
}
}
}
//---------------------------------------------------------------------------
void vtkSMSessionProxyManager::MarkProxyAsModified(vtkSMProxy* proxy)
{
this->Internals->ModifiedProxies.insert(proxy);
}
//---------------------------------------------------------------------------
void vtkSMSessionProxyManager::UnMarkProxyAsModified(vtkSMProxy* proxy)
{
vtkSMSessionProxyManagerInternals::SetOfProxies::iterator it =
this->Internals->ModifiedProxies.find(proxy);
if (it != this->Internals->ModifiedProxies.end())
{
this->Internals->ModifiedProxies.erase(it);
}
}
//---------------------------------------------------------------------------
int vtkSMSessionProxyManager::AreProxiesModified()
{
return (this->Internals->ModifiedProxies.size() > 0)? 1: 0;
}
//---------------------------------------------------------------------------
void vtkSMSessionProxyManager::LoadXMLState( const char* filename,
vtkSMStateLoader* loader/*=NULL*/)
{
vtkPVXMLParser* parser = vtkPVXMLParser::New();
parser->SetFileName(filename);
parser->Parse();
this->LoadXMLState(parser->GetRootElement(), loader);
parser->Delete();
}
//---------------------------------------------------------------------------
void vtkSMSessionProxyManager::LoadXMLState( vtkPVXMLElement* rootElement,
vtkSMStateLoader* loader/*=NULL*/,
bool keepOriginalIds/*=false*/)
{
if (!rootElement)
{
return;
}
vtkSmartPointer<vtkSMStateLoader> spLoader;
if (!loader)
{
spLoader = vtkSmartPointer<vtkSMStateLoader>::New();
spLoader->SetSessionProxyManager(this);
}
else
{
spLoader = loader;
}
if (spLoader->LoadState(rootElement, keepOriginalIds))
{
vtkSMProxyManager::LoadStateInformation info;
info.RootElement = rootElement;
info.ProxyLocator = spLoader->GetProxyLocator();
this->InvokeEvent(vtkCommand::LoadStateEvent, &info);
}
}
//---------------------------------------------------------------------------
void vtkSMSessionProxyManager::SaveXMLState(const char* filename)
{
vtkPVXMLElement* rootElement = this->SaveXMLState();
ofstream os(filename, ios::out);
rootElement->PrintXML(os, vtkIndent());
rootElement->Delete();
}
//---------------------------------------------------------------------------
vtkPVXMLElement* vtkSMSessionProxyManager::SaveXMLState()
{
vtkPVXMLElement* root = vtkPVXMLElement::New();
root->SetName("GenericParaViewApplication");
this->AddInternalState(root);
vtkSMProxyManager::LoadStateInformation info;
info.RootElement = root;
info.ProxyLocator = NULL;
this->InvokeEvent(vtkCommand::SaveStateEvent, &info);
return root;
}
//---------------------------------------------------------------------------
void vtkSMSessionProxyManager::CollectReferredProxies(
vtkSMProxyManagerProxySet& setOfProxies, vtkSMProxy* proxy)
{
vtkSmartPointer<vtkSMPropertyIterator> iter;
iter.TakeReference(proxy->NewPropertyIterator());
for (iter->Begin(); !iter->IsAtEnd(); iter->Next())
{
vtkSMProxyProperty* pp = vtkSMProxyProperty::SafeDownCast(
iter->GetProperty());
for (unsigned int cc=0; pp && (pp->GetNumberOfProxies() > cc); cc++)
{
vtkSMProxy* referredProxy = pp->GetProxy(cc);
if (referredProxy)
{
setOfProxies.insert(referredProxy);
this->CollectReferredProxies(setOfProxies, referredProxy);
}
}
}
}
//---------------------------------------------------------------------------
vtkPVXMLElement* vtkSMSessionProxyManager::AddInternalState(vtkPVXMLElement *parentElem)
{
vtkPVXMLElement* rootElement = vtkPVXMLElement::New();
rootElement->SetName("ServerManagerState");
// Set version number on the state element.
std::ostringstream version_string;
version_string << vtkSMProxyManager::GetVersionMajor() << "."
<< vtkSMProxyManager::GetVersionMinor() << "."
<< vtkSMProxyManager::GetVersionPatch();
rootElement->AddAttribute("version", version_string.str().c_str());
std::set<vtkSMProxy*> visited_proxies; // set of proxies already added.
// First save the state of all proxies
vtkSMSessionProxyManagerInternals::ProxyGroupType::iterator it =
this->Internals->RegisteredProxyMap.begin();
for (; it != this->Internals->RegisteredProxyMap.end(); it++)
{
vtkSMProxyManagerProxyMapType::iterator it2 =
it->second.begin();
const char* colname = it->first.c_str();
// Do not save the state of global_properties nor settings.
const char* global_properties = "global_properties";
const char* settings = "settings";
if (strcmp(global_properties, colname) == 0 ||
strcmp(settings, colname) == 0)
{
continue;
}
// Do not save the state of prototypes.
const char* protstr = "_prototypes";
int do_group = 1;
if (strlen(colname) > strlen(protstr))
{
const char* newstr = colname + strlen(colname) -
strlen(protstr);
if (strcmp(newstr, protstr) == 0)
{
do_group = 0;
}
}
else if ( colname[0] == '_' )
{
do_group = 0;
}
if (!do_group)
{
continue;
}
// save the states of all proxies in this group.
for (; it2 != it->second.end(); it2++)
{
vtkSMProxyManagerProxyListType::iterator it3
= it2->second.begin();
for (; it3 != it2->second.end(); ++it3)
{
if (visited_proxies.find(it3->GetPointer()->Proxy.GetPointer())
!= visited_proxies.end())
{
// proxy has been saved.
continue;
}
it3->GetPointer()->Proxy.GetPointer()->SaveXMLState(rootElement);
visited_proxies.insert(it3->GetPointer()->Proxy.GetPointer());
}
}
}
// Save the proxy collections. This is done separately because
// one proxy can be in more than one group.
it = this->Internals->RegisteredProxyMap.begin();
for (; it != this->Internals->RegisteredProxyMap.end(); it++)
{
// Do not save the state of options
const char* options = "settings";
if (strcmp(options, it->first.c_str()) == 0)
{
continue;
}
// Do not save the state of prototypes.
const char* protstr = "_prototypes";
int do_group = 1;
if (strlen(it->first.c_str()) > strlen(protstr))
{
const char* newstr = it->first.c_str() + strlen(it->first.c_str()) -
strlen(protstr);
if (strcmp(newstr, protstr) == 0)
{
do_group = 0;
}
}
if (do_group)
{
vtkPVXMLElement* collectionElement = vtkPVXMLElement::New();
collectionElement->SetName("ProxyCollection");
collectionElement->AddAttribute("name", it->first.c_str());
vtkSMProxyManagerProxyMapType::iterator it2 =
it->second.begin();
bool some_proxy_added = false;
for (; it2 != it->second.end(); it2++)
{
vtkSMProxyManagerProxyListType::iterator it3 =
it2->second.begin();
for (; it3 != it2->second.end(); ++it3)
{
if (visited_proxies.find(it3->GetPointer()->Proxy.GetPointer()) != visited_proxies.end())
{
vtkPVXMLElement* itemElement = vtkPVXMLElement::New();
itemElement->SetName("Item");
itemElement->AddAttribute("id",
it3->GetPointer()->Proxy->GetGlobalID());
itemElement->AddAttribute("name", it2->first.c_str());
collectionElement->AddNestedElement(itemElement);
itemElement->Delete();
some_proxy_added = true;
}
}
}
// Avoid addition of empty groups.
if (some_proxy_added)
{
rootElement->AddNestedElement(collectionElement);
}
collectionElement->Delete();
}
}
// TODO: Save definitions for only referred compound proxy definitions
// when saving state for subset of proxies.
vtkPVXMLElement* defs = vtkPVXMLElement::New();
defs->SetName("CustomProxyDefinitions");
this->SaveCustomProxyDefinitions(defs);
rootElement->AddNestedElement(defs);
defs->Delete();
// Save links
vtkPVXMLElement* links = vtkPVXMLElement::New();
links->SetName("Links");
this->SaveRegisteredLinks(links);
rootElement->AddNestedElement(links);
vtkSMProxy* globalPropertiesProxy = this->GetProxy("global_properties", "ColorPalette");
if (globalPropertiesProxy)
{
globalPropertiesProxy->SaveXMLState(links);
}
links->Delete();
if (parentElem)
{
parentElem->AddNestedElement(rootElement);
rootElement->FastDelete();
}
return rootElement;
}
//---------------------------------------------------------------------------
void vtkSMSessionProxyManager::UnRegisterCustomProxyDefinitions()
{
assert(this->ProxyDefinitionManager != 0);
this->ProxyDefinitionManager->ClearCustomProxyDefinitions();
}
//---------------------------------------------------------------------------
void vtkSMSessionProxyManager::UnRegisterCustomProxyDefinition(
const char* group, const char* name)
{
assert(this->ProxyDefinitionManager != 0);
this->ProxyDefinitionManager->RemoveCustomProxyDefinition(group, name);
}
//---------------------------------------------------------------------------
void vtkSMSessionProxyManager::RegisterCustomProxyDefinition(
const char* group, const char* name, vtkPVXMLElement* top)
{
assert(this->ProxyDefinitionManager != 0);
this->ProxyDefinitionManager->AddCustomProxyDefinition(group, name, top);
}
//---------------------------------------------------------------------------
// Does not raise an error if definition is not found.
vtkPVXMLElement* vtkSMSessionProxyManager::GetProxyDefinition(
const char* group, const char* name)
{
if (!name || !group)
{
return 0;
}
assert(this->ProxyDefinitionManager != 0);
return this->ProxyDefinitionManager->GetProxyDefinition(group, name, false);
}
//---------------------------------------------------------------------------
void vtkSMSessionProxyManager::LoadCustomProxyDefinitions(vtkPVXMLElement* root)
{
assert(this->ProxyDefinitionManager != 0);
this->ProxyDefinitionManager->LoadCustomProxyDefinitions(root);
}
//---------------------------------------------------------------------------
void vtkSMSessionProxyManager::LoadCustomProxyDefinitions(const char* filename)
{
assert(this->ProxyDefinitionManager != 0);
vtkPVXMLParser* parser = vtkPVXMLParser::New();
parser->SetFileName(filename);
if (!parser->Parse())
{
vtkErrorMacro("Failed to parse file : " << filename);
return;
}
this->ProxyDefinitionManager->LoadCustomProxyDefinitions(parser->GetRootElement());
parser->Delete();
}
//---------------------------------------------------------------------------
void vtkSMSessionProxyManager::SaveCustomProxyDefinitions(
vtkPVXMLElement* rootElement)
{
assert("Definition Manager should exist" && this->ProxyDefinitionManager != 0);
this->ProxyDefinitionManager->SaveCustomProxyDefinitions(rootElement);
}
//---------------------------------------------------------------------------
void vtkSMSessionProxyManager::SaveRegisteredLinks(vtkPVXMLElement* rootElement)
{
vtkSMSessionProxyManagerInternals::LinkType::iterator it =
this->Internals->RegisteredLinkMap.begin();
for (; it != this->Internals->RegisteredLinkMap.end(); ++it)
{
it->second.GetPointer()->SaveXMLState(it->first.c_str(), rootElement);
}
}
//---------------------------------------------------------------------------
vtkPVXMLElement* vtkSMSessionProxyManager::GetProxyHints(
const char* groupName, const char* proxyName)
{
if (!groupName || !proxyName)
{
return 0;
}
vtkSMProxy* proxy = this->GetPrototypeProxy(groupName, proxyName);
return proxy? proxy->GetHints() : NULL;
}
//---------------------------------------------------------------------------
vtkPVXMLElement* vtkSMSessionProxyManager::GetPropertyHints(
const char* groupName, const char* proxyName, const char* propertyName)
{
if (!groupName || !proxyName || !propertyName)
{
return 0;
}
vtkSMProxy* proxy = this->GetPrototypeProxy(groupName, proxyName);
if (proxy)
{
vtkSMProperty* prop = proxy->GetProperty(propertyName);
if (prop)
{
return prop->GetHints();
}
}
return 0;
}
//---------------------------------------------------------------------------
bool vtkSMSessionProxyManager::LoadConfigurationXML(const char* xml)
{
assert(this->ProxyDefinitionManager != 0);
return this->ProxyDefinitionManager->LoadConfigurationXMLFromString(xml);
}
//---------------------------------------------------------------------------
void vtkSMSessionProxyManager::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
os << indent << "UpdateInputProxies: " << this->UpdateInputProxies << endl;
}
//---------------------------------------------------------------------------
const vtkSMMessage* vtkSMSessionProxyManager::GetFullState()
{
if(!this->Internals->State.has_global_id())
{
this->Internals->State.set_global_id(vtkSMSessionProxyManager::GetReservedGlobalID());
this->Internals->State.set_location(vtkProcessModule::PROCESS_DATA_SERVER);
this->Internals->State.SetExtension(DefinitionHeader::client_class, "");
this->Internals->State.SetExtension(DefinitionHeader::server_class, "vtkSIObject");
this->Internals->State.SetExtension(ProxyState::xml_group, "");
this->Internals->State.SetExtension(ProxyState::xml_name, "");
}
return &this->Internals->State;
}
//---------------------------------------------------------------------------
void vtkSMSessionProxyManager::LoadState(const vtkSMMessage* msg, vtkSMProxyLocator* locator)
{
// Disable state push
bool previous = this->StateUpdateNotification;
this->StateUpdateNotification = false;
// Need to compute differences and just call Register/UnRegister for those items
std::set<vtkSMProxyManagerEntry> tuplesToUnregister;
std::set<vtkSMProxyManagerEntry> tuplesToRegister;
std::set<vtkSMProxyManagerEntry>::iterator iter;
// Fill delta sets
this->Internals->ComputeDelta(msg, locator, tuplesToRegister, tuplesToUnregister);
// Register new ones
iter = tuplesToRegister.begin();
while( iter != tuplesToRegister.end() )
{
this->RegisterProxy(iter->Group.c_str(), iter->Name.c_str(), iter->Proxy);
iter++;
}
// Unregister old ones
iter = tuplesToUnregister.begin();
while( iter != tuplesToUnregister.end() )
{
this->UnRegisterProxy(iter->Group.c_str(), iter->Name.c_str(), iter->Proxy);
iter++;
}
// Manage ProxySelectionModel state
for(int i = 0,
size = msg->ExtensionSize(PXMRegistrationState::registered_selection_model);
i < size && this->Session;
i++)
{
vtkTypeUInt32 remoteObjectId =
msg->GetExtension(PXMRegistrationState::registered_selection_model, i).global_id();
const char* name =
msg->GetExtension(PXMRegistrationState::registered_selection_model, i).name().c_str();
vtkSMProxySelectionModel* model = this->GetSelectionModel(name);
// Make sure the expected selection model exist by creating a new empty one
// that will be filled by the LoadState
if(model == NULL)
{
model = vtkSMProxySelectionModel::New();
this->RegisterSelectionModel(name, model);
model->FastDelete();
}
if(!model->HasGlobalID())
{
vtkSMMessage msgTmp;
msgTmp.set_global_id(remoteObjectId);
msgTmp.set_location(vtkPVSession::DATA_SERVER_ROOT);
this->Session->PullState(&msgTmp);
model->LoadState(&msgTmp, locator);
}
}
// Manage Link state
std::set<std::string> linkNameToKeep;
for(int i = 0,
size = msg->ExtensionSize(PXMRegistrationState::registered_link);
i < size && this->Session;
i++)
{
vtkTypeUInt32 remoteObjectId =
msg->GetExtension(PXMRegistrationState::registered_link, i).global_id();
const char* name =
msg->GetExtension(PXMRegistrationState::registered_link, i).name().c_str();
linkNameToKeep.insert(name);
vtkSMLink* link = this->GetRegisteredLink(name);
if(link)
{
// Do nothing as we already know about it
}
else if ((link =
vtkSMLink::SafeDownCast(
this->Session->GetRemoteObject(remoteObjectId))) != NULL)
{
// The link exist but is not registered
this->RegisterLink(name, link);
}
else
{
// We need to create that link, load its state and register it
vtkSMMessage msgTmp;
msgTmp.set_global_id(remoteObjectId);
msgTmp.set_location(vtkPVSession::DATA_SERVER_ROOT);
this->Session->PullState(&msgTmp);
// Create the concreate class
vtkObject* object;
const char* className = msgTmp.GetExtension(DefinitionHeader::client_class).c_str();
object = vtkPVInstantiator::CreateInstance(className);
if (!object)
{
vtkErrorMacro("Did not create Link concreate class of " << className);
abort();
}
link = vtkSMLink::SafeDownCast(object);
if(link)
{
link->LoadState(&msgTmp, locator);
this->RegisterLink(name, link);
}
object->Delete();
}
}
// Remove Link that have disapeared...
for(int i = 0; i < this->GetNumberOfLinks(); i++)
{
const char* currentLinkName = this->GetLinkName(i);
if(linkNameToKeep.find(currentLinkName) == linkNameToKeep.end())
{
this->UnRegisterLink(currentLinkName);
i--;
}
}
// Update state
this->Internals->UpdateProxySelectionModelState();
this->Internals->UpdateLinkState();
// Share it
this->StateUpdateNotification = previous;
this->TriggerStateUpdate();
}
//---------------------------------------------------------------------------
bool vtkSMSessionProxyManager::HasDefinition( const char* groupName,
const char* proxyName )
{
return this->ProxyDefinitionManager &&
this->ProxyDefinitionManager->HasDefinition(groupName, proxyName);
}
//---------------------------------------------------------------------------
void vtkSMSessionProxyManager::RegisterSelectionModel(
const char* name, vtkSMProxySelectionModel* model)
{
if (!model)
{
vtkErrorMacro("Cannot register a null model.");
return;
}
if (!name)
{
vtkErrorMacro("Cannot register model with no name.");
return;
}
vtkSMProxySelectionModel* curmodel = this->GetSelectionModel(name);
if (curmodel && curmodel == model)
{
// already registered.
return;
}
if (curmodel)
{
vtkWarningMacro("Replacing existing selection model: " << name);
}
model->SetSession(this->GetSession());
this->Internals->SelectionModels[name] = model;
}
//---------------------------------------------------------------------------
void vtkSMSessionProxyManager::UnRegisterSelectionModel( const char* name)
{
this->Internals->SelectionModels.erase(name);
}
//---------------------------------------------------------------------------
vtkSMProxySelectionModel* vtkSMSessionProxyManager::GetSelectionModel(
const char* name)
{
vtkSMSessionProxyManagerInternals::SelectionModelsType::iterator iter =
this->Internals->SelectionModels.find(name);
if (iter == this->Internals->SelectionModels.end())
{
return 0;
}
return iter->second;
}
//---------------------------------------------------------------------------
vtkIdType vtkSMSessionProxyManager::GetNumberOfSelectionModel()
{
return static_cast<vtkIdType>(this->Internals->SelectionModels.size());
}
//---------------------------------------------------------------------------
vtkSMProxySelectionModel* vtkSMSessionProxyManager::GetSelectionModelAt(int idx)
{
vtkSMSessionProxyManagerInternals::SelectionModelsType::iterator iter =
this->Internals->SelectionModels.begin();
for(int i=0;i<idx;i++)
{
if(iter == this->Internals->SelectionModels.end())
{
// Out of range
return NULL;
}
iter++;
}
return iter->second;
}
//----------------------------------------------------------------------------
void vtkSMSessionProxyManager::UpdateFromRemote()
{
if (this->Session)
{
// For collaboration purpose at connection time we synchronize our
// ProxyManager state with the server
if(this->Session->IsMultiClients())
{
vtkSMMessage msg;
msg.set_global_id(vtkSMSessionProxyManager::GetReservedGlobalID());
msg.set_location(vtkPVSession::DATA_SERVER_ROOT);
this->Session->PullState(&msg);
if(msg.ExtensionSize(PXMRegistrationState::registered_proxy) > 0)
{
// We take the parent locator to always refer to the server while loading
// the state. This prevent us from getting a creation state instead of
// full update state when we split the creation/update action in 2
// separate call.
// Moreover, we don't want any existing states to be pushed again to
// the server.
bool previousValue = this->Session->StartProcessingRemoteNotification();
// Setup server only state/proxy Locator
vtkNew<vtkSMDeserializerProtobuf> deserializer;
deserializer->SetStateLocator(this->Session->GetStateLocator()->GetParentLocator());
deserializer->SetSessionProxyManager(this);
vtkNew<vtkSMProxyLocator> serverLocator;
serverLocator->SetDeserializer(deserializer.GetPointer());
serverLocator->UseSessionToLocateProxy(true);
serverLocator->SetSession(this->Session);
// Load and update
vtkSMProxyProperty::EnableProxyCreation();
this->LoadState( &msg, serverLocator.GetPointer());
this->UpdateRegisteredProxies(0);
vtkSMProxyProperty::DisableProxyCreation();
this->Session->StopProcessingRemoteNotification(previousValue);
}
}
}
}
//---------------------------------------------------------------------------
bool vtkSMSessionProxyManager::IsStateUpdateNotificationEnabled()
{
return this->StateUpdateNotification;
}
//---------------------------------------------------------------------------
void vtkSMSessionProxyManager::DisableStateUpdateNotification()
{
this->StateUpdateNotification = false;
}
//---------------------------------------------------------------------------
void vtkSMSessionProxyManager::EnableStateUpdateNotification()
{
this->StateUpdateNotification = true;
}
//---------------------------------------------------------------------------
void vtkSMSessionProxyManager::TriggerStateUpdate()
{
if(this->PipelineState && this->StateUpdateNotification)
{
this->Internals->UpdateProxySelectionModelState();
this->PipelineState->ValidateState();
}
}
//----------------------------------------------------------------------------
vtkSMProxy* vtkSMSessionProxyManager::FindProxy(
const char* reggroup, const char* xmlgroup, const char* xmltype)
{
vtkNew<vtkSMProxyIterator> iter;
iter->SetSessionProxyManager(this);
iter->SetModeToOneGroup();
for (iter->Begin(reggroup); !iter->IsAtEnd(); iter->Next())
{
vtkSMProxy* proxy = iter->GetProxy();
if (proxy != NULL &&
proxy->GetXMLGroup() &&
proxy->GetXMLName() &&
strcmp(proxy->GetXMLGroup(), xmlgroup) == 0 &&
strcmp(proxy->GetXMLName(), xmltype) == 0)
{
return proxy;
}
}
return NULL;
}
|