File size: 43,532 Bytes
68ce2fc | 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 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ex: set filetype=cpp softtabstop=4 shiftwidth=4 tabstop=4 cindent expandtab: */
/*
Author(s): Anton Deguet
Created on: 2008-01-17
(C) Copyright 2008-2026 Johns Hopkins University (JHU), All Rights Reserved.
--- begin cisst license - do not edit ---
This software is provided "as is" under an open source license, with
no warranty. The complete license can be found in license.txt and
http://www.cisst.org/cisst/license.txt.
--- end cisst license ---
*/
%module cisstMultiTaskPython
%include "std_string.i"
%include "std_vector.i"
%include "std_map.i"
%include "std_pair.i"
%include "std_streambuf.i"
%include "std_iostream.i"
%include "swigrun.i"
%import "cisstConfig.h"
%import "cisstCommon/cisstCommon.i"
%import "cisstVector/cisstVector.i"
%import "cisstOSAbstraction/cisstOSAbstraction.i"
%import "cisstMultiTask/mtsConfig.h"
%init %{
import_array() // numpy initialization
%}
%header %{
#include <cisstMultiTask/mtsPython.h>
%}
// use class type to create the correct Python type
%apply cmnGenericObject * {mtsGenericObject *};
%template(mtsStringVector) std::vector<std::string>;
%template(mtsDoubleVector) std::vector<double>;
// Generate parameter documentation for IRE
%feature("autodoc", "1");
%ignore *::AddCommandVoid;
%ignore *::AddEventVoid;
%ignore mtsComponent::AddRequiredInterface;
%ignore mtsComponent::AddProvidedInterface;
%ignore mtsManagerLocal::AddTask;
%ignore mtsManagerLocal::GetTask;
%ignore mtsManagerLocal::AddDevice;
%ignore mtsManagerLocal::GetDevice;
#define CISST_EXPORT
#define CISST_DEPRECATED
// enums defined in mtsForwardDeclarations
%include "cisstMultiTask/mtsForwardDeclarations.h"
%include "cisstMultiTask/mtsExecutionResult.h"
// Wrap base class
%include "cisstMultiTask/mtsGenericObject.h"
// Wrap commands
%include "cisstMultiTask/mtsCommandBase.h"
%include "cisstMultiTask/mtsCommandVoid.h"
%include "cisstMultiTask/mtsCommandVoidReturn.h"
%include "cisstMultiTask/mtsCommandRead.h"
%include "cisstMultiTask/mtsCommandWriteBase.h"
%include "cisstMultiTask/mtsCommandWriteReturn.h"
%include "cisstMultiTask/mtsCommandQualifiedRead.h"
%include "cisstMultiTask/mtsCommandVoidReturn.h"
// Wrap event receivers
%include "cisstMultiTask/mtsEventReceiver.h"
// Extend mtsCommandVoid
%extend mtsCommandVoid {
%pythoncode %{
def __call__(self):
return self.Execute(MTS_NOT_BLOCKING).GetResult()
%}
}
// Extend mtsCommandVoidReturn
%extend mtsCommandVoidReturn {
%pythoncode %{
def UpdateFromC(self):
try:
tmpObject = self.GetResultPrototype().Services().Create()
self.ArgumentType = tmpObject.__class__
except Exception as e:
print('VoidReturn command ' + self.GetName() + ': ' + str(e))
def __call__(self):
# PK: figure out if the first statement (after try) is still needed
try:
argument = self.ArgumentType(self.GetResultPrototype())
except Exception:
argument = self.GetResultPrototype()
# Probably should check return value below
self.Execute(argument)
# If argument has a GetDataCopy method, we assume it is derived from
# mtsGenericObjectProxy (%extend is used to add this method).
if hasattr(argument,"GetDataCopy"):
return argument.GetDataCopy()
else:
return argument
%}
}
// Extend mtsCommandWrite
%extend mtsCommandWriteBase {
%pythoncode %{
def UpdateFromC(self):
try:
tmpObject = self.GetArgumentClassServices().Create()
self.ArgumentType = tmpObject.__class__
except Exception as e:
print('Write command ' + self.GetName() + ': ' + str(e))
def __call__(self, argument):
if isinstance(argument, self.ArgumentType):
return self.Execute(argument, MTS_NOT_BLOCKING).GetResult()
else:
realArgument = self.ArgumentType(argument)
return self.Execute(realArgument, MTS_NOT_BLOCKING).GetResult()
%}
}
// Extend mtsCommandWriteReturn
%extend mtsCommandWriteReturn {
%pythoncode %{
def UpdateFromC(self):
try:
tmp1Object = self.GetArgumentPrototype().Services().Create()
self.ArgumentType = tmp1Object.__class__
tmp2Object = self.GetResultPrototype().Services().Create()
self.ResultType = tmp2Object.__class__
except Exception as e:
print('WriteReturn command ' + self.GetName() + ': ' + str(e))
def __call__(self, argument):
result = self.ResultType(self.GetResultPrototype())
# Probably should check return value of self.Execute
if isinstance(argument, self.ArgumentType):
self.Execute(argument, result)
else:
realArgument = self.ArgumentType(argument1)
self.Execute(realArgument, result)
# If result has a GetDataCopy method, we assume it is derived from
# mtsGenericObjectProxy (%extend is used to add this method).
if hasattr(result,"GetDataCopy"):
return result.GetDataCopy()
else:
return result
%}
}
// Extend mtsCommandRead
%extend mtsCommandRead {
%pythoncode %{
def UpdateFromC(self):
try:
tmpObject = self.GetArgumentPrototype().Services().Create()
self.ArgumentType = tmpObject.__class__
except Exception as e:
print('Read command ' + self.GetName() + ': ' + str(e))
except AttributeError as e:
print('Read command ' + self.GetName() + ': ' + str(e))
def __call__(self):
# PK: figure out if the first statement (after try) is still needed
try:
argument = self.ArgumentType(self.GetArgumentPrototype())
except Exception:
argument = self.GetArgumentPrototype()
# Probably should check return value below
self.Execute(argument)
# If argument has a GetDataCopy method, we assume it is derived from
# mtsGenericObjectProxy (%extend is used to add this method).
if hasattr(argument,"GetDataCopy"):
return argument.GetDataCopy()
else:
return argument
%}
}
// Extend mtsCommandQualifiedRead
%extend mtsCommandQualifiedRead {
%pythoncode %{
def UpdateFromC(self):
try:
tmp1Object = self.GetArgument1Prototype().Services().Create()
self.Argument1Type = tmp1Object.__class__
tmp2Object = self.GetArgument2Prototype().Services().Create()
self.Argument2Type = tmp2Object.__class__
except Exception as e:
print('Qualified read command ' + self.GetName() + ': ' + str(e))
def __call__(self, argument1):
argument2 = self.Argument2Type(self.GetArgument2Prototype())
# Probably should check return value of self.Execute
if isinstance(argument1, self.Argument1Type):
self.Execute(argument1, argument2)
else:
realArgument1 = self.Argument1Type(argument1)
self.Execute(realArgument1, argument2)
# If argument2 has a GetDataCopy method, we assume it is derived from
# mtsGenericObjectProxy (%extend is used to add this method).
if hasattr(argument2,"GetDataCopy"):
return argument2.GetDataCopy()
else:
return argument2
%}
}
// Wrap functions
%include "cisstMultiTask/mtsFunctionBase.h"
%include "cisstMultiTask/mtsFunctionVoid.h"
%include "cisstMultiTask/mtsFunctionVoidReturn.h"
%include "cisstMultiTask/mtsFunctionRead.h"
%include "cisstMultiTask/mtsFunctionWrite.h"
%include "cisstMultiTask/mtsFunctionWriteReturn.h"
%include "cisstMultiTask/mtsFunctionQualifiedRead.h"
// Extend mtsFunctionVoid
%extend mtsFunctionVoid {
%pythoncode %{
def __call__(self):
return self.Execute().GetResult()
%}
}
// Extend mtsFunctionVoidReturn
%extend mtsFunctionVoidReturn {
%pythoncode %{
def UpdateFromC(self):
if self.IsValid():
try:
tmpObject = self.GetResultPrototype().Services().Create()
self.ArgumentType = tmpObject.__class__
except Exception as e:
print('VoidReturn function ' + self.GetCommand().GetName() + ': ' + str(e))
else:
print('VoidReturn function not valid')
def __call__(self):
# PK: figure out if the first statement (after try) is still needed
try:
argument = self.ArgumentType(self.GetResultPrototype())
except Exception:
argument = self.GetResultPrototype()
# Probably should check return value below
self.ExecuteGeneric(argument)
# If argument has a GetDataCopy method, we assume it is derived from
# mtsGenericObjectProxy (%extend is used to add this method).
if hasattr(argument,"GetDataCopy"):
return argument.GetDataCopy()
else:
return argument
%}
}
// Extend mtsFunctionRead
%extend mtsFunctionRead {
%pythoncode %{
def UpdateFromC(self):
if self.IsValid():
try:
tmpObject = self.GetArgumentPrototype().Services().Create()
self.ArgumentType = tmpObject.__class__
except Exception as e:
print('Read function ' + self.GetCommand().GetName() + ': ' + str(e))
else:
print('Read function not valid')
def __call__(self):
# PK: figure out if the first statement (after try) is still needed
try:
argument = self.ArgumentType(self.GetArgumentPrototype())
except Exception:
argument = self.GetArgumentPrototype()
# Probably should check return value below
self.ExecuteGeneric(argument)
# If argument has a GetDataCopy method, we assume it is derived from
# mtsGenericObjectProxy (%extend is used to add this method).
if hasattr(argument,"GetDataCopy"):
return argument.GetDataCopy()
else:
return argument
%}
}
// Extend mtsFunctionWrite
%extend mtsFunctionWrite {
%pythoncode %{
def UpdateFromC(self):
if self.IsValid():
try:
tmpObject = self.GetArgumentPrototype().Services().Create()
self.ArgumentType = tmpObject.__class__
except Exception as e:
print('Write function ' + self.GetCommand().GetName() + ': ' + str(e))
else:
print('Write function not valid')
def __call__(self, argument):
if isinstance(argument, self.ArgumentType):
return self.ExecuteGeneric(argument).GetResult()
else:
realArgument = self.ArgumentType(argument)
return self.ExecuteGeneric(realArgument).GetResult()
%}
}
// Extend mtsFunctionWriteReturn
%extend mtsFunctionWriteReturn {
%pythoncode %{
def UpdateFromC(self):
if self.IsValid():
try:
tmp1Object = self.GetArgumentPrototype().Services().Create()
self.ArgumentType = tmp1Object.__class__
tmp2Object = self.GetResultPrototype().Services().Create()
self.ResultType = tmp2Object.__class__
except Exception as e:
print('WriteReturn function ' + self.GetCommand().GetName() + ': ' + str(e))
else:
print('WriteReturn function not valid')
def __call__(self, argument):
result = self.ResultType(self.GetResultPrototype())
# Probably should check return value of self.Execute
if isinstance(argument, self.ArgumentType):
self.ExecuteGeneric(argument, result)
else:
realArgument = self.ArgumentType(argument1)
self.ExecuteGeneric(realArgument, result)
# If result has a GetDataCopy method, we assume it is derived from
# mtsGenericObjectProxy (%extend is used to add this method).
if hasattr(result,"GetDataCopy"):
return result.GetDataCopy()
else:
return result
%}
}
// Extend mtsFunctionQualifiedRead
%extend mtsFunctionQualifiedRead {
%pythoncode %{
def UpdateFromC(self):
if self.IsValid():
try:
tmp1Object = self.GetArgument1Prototype().Services().Create()
self.Argument1Type = tmp1Object.__class__
tmp2Object = self.GetArgument2Prototype().Services().Create()
self.Argument2Type = tmp2Object.__class__
except Exception as e:
print('Qualified read function ' + self.GetCommand().GetName() + ': ' + str(e))
else:
print('QualifiedRead function not valid')
def __call__(self, argument1):
argument2 = self.Argument2Type(self.GetArgument2Prototype())
# Probably should check return value of self.Execute
if isinstance(argument1, self.Argument1Type):
self.ExecuteGeneric(argument1, argument2)
else:
realArgument1 = self.Argument1Type(argument1)
self.ExecuteGeneric(realArgument1, argument2)
# If argument2 has a GetDataCopy method, we assume it is derived from
# mtsGenericObjectProxy (%extend is used to add this method).
if hasattr(argument2,"GetDataCopy"):
return argument2.GetDataCopy()
else:
return argument2
%}
}
// Wrap tasks and components
%include "cisstMultiTask/mtsComponent.h"
%template(mtsComponentConstructorNameAndInt) mtsComponentConstructorNameAndArg<int>;
%template(mtsComponentConstructorNameAndUInt) mtsComponentConstructorNameAndArg<unsigned int>;
%template(mtsComponentConstructorNameAndLong) mtsComponentConstructorNameAndArg<long>;
%template(mtsComponentConstructorNameAndULong) mtsComponentConstructorNameAndArg<unsigned long>;
%template(mtsComponentConstructorNameAndDouble) mtsComponentConstructorNameAndArg<double>;
%template(mtsComponentConstructorNameAndString) mtsComponentConstructorNameAndArg<std::string>;
%extend mtsComponent {
%pythoncode %{
def UpdateFromC(self):
interfaces = mtsComponent.GetNamesOfInterfacesProvided(self)
for interface in interfaces:
interfaceNoSpace = interface.replace(' ', '')
interfaceFrontEnd = mtsComponent.GetInterfaceProvided(self, interface)
self.__dict__[interfaceNoSpace] = mtsInterfaceProvided.GetEndUserInterface(interfaceFrontEnd, 'Python')
self.__dict__[interfaceNoSpace].UpdateFromC()
interfaces = mtsComponent.GetNamesOfInterfacesRequired(self)
for interface in interfaces:
interfaceNoSpace = interface.replace(' ', '')
self.__dict__[interfaceNoSpace] = mtsComponent.GetInterfaceRequired(self, interface)
# Only call UpdateFromC if required interface is connected to a provided interface
if self.__dict__[interfaceNoSpace].GetConnectedInterface():
self.__dict__[interfaceNoSpace].UpdateFromC()
def AddInterfaceRequiredFromProvided(self, interfaceProvided, interfaceRequiredName = ''):
if not isinstance(interfaceProvided, mtsInterfaceProvidedDescription):
print('Parameter must be of type mtsInterfaceProvidedDescription')
return
if not interfaceRequiredName:
interfaceProvidedNoSpace = interfaceProvided.InterfaceName.replace(' ', '')
interfaceRequiredName = 'RequiredFor' + interfaceProvidedNoSpace
else:
interfaceRequiredName = interfaceRequiredName.replace(' ', '')
interfaceRequired = self.AddInterfaceRequired(interfaceRequiredName, MTS_OPTIONAL)
if not interfaceRequired:
return
self.__dict__[interfaceRequired.GetName()] = interfaceRequired
for command in interfaceProvided.CommandsVoid:
func = mtsFunctionVoid()
interfaceRequired.AddFunction(command.Name, func)
func.thisown = 0
for command in interfaceProvided.CommandsVoidReturn:
func = mtsFunctionVoidReturn()
interfaceRequired.AddFunction(command.Name, func)
func.thisown = 0
for command in interfaceProvided.CommandsWrite:
func = mtsFunctionWrite()
interfaceRequired.AddFunction(command.Name, func)
func.thisown = 0
for command in interfaceProvided.CommandsWriteReturn:
func = mtsFunctionWriteReturn()
interfaceRequired.AddFunction(command.Name, func)
func.thisown = 0
for command in interfaceProvided.CommandsQualifiedRead:
func = mtsFunctionQualifiedRead()
interfaceRequired.AddFunction(command.Name, func)
func.thisown = 0
for command in interfaceProvided.CommandsRead:
func = mtsFunctionRead()
interfaceRequired.AddFunction(command.Name, func)
func.thisown = 0
return interfaceRequired
# otherComponentInterface should be a tuple ('process', 'component', 'interfaceProvided')
# or ('component', 'interfaceProvided')
def AddInterfaceRequiredAndConnect(self, otherComponentInterface):
try:
LCM = mtsManagerLocal.GetInstance()
localProcessName = LCM.GetProcessName()
num = len(otherComponentInterface)
if 2 <= num <= 3:
interfaceName = otherComponentInterface[num-1]
componentName = otherComponentInterface[num-2]
if num == 3:
processName = otherComponentInterface[num-3]
else:
processName = localProcessName
interfaceDescription = LCM.GetInterfaceProvidedDescription(processName, componentName, interfaceName)
if not interfaceDescription.InterfaceName:
print('No provided interface (empty string)')
return None
interfaceRequiredName = 'RequiredFor' + componentName + '_' + interfaceName;
interfaceRequired = self.AddInterfaceRequiredFromProvided(interfaceDescription, interfaceRequiredName)
if (processName != localProcessName):
LCM.Connect(localProcessName, self.GetName(), interfaceRequired.GetName(),
processName, componentName, interfaceName)
else:
LCM.Connect(self.GetName(), interfaceRequired.GetName(), componentName, interfaceName)
interfaceRequired.UpdateFromC()
if interfaceRequired.GetConnectedInterface():
print('Required interface ' + interfaceRequired.GetName() + ' connected.')
else:
print('Required interface ' + interfaceRequired.GetName() + ' not connected.')
return interfaceRequired
else:
print('Parameter error: must specify (process, component, interface) or (component, interface)')
except TypeError as e:
print('Parameter error: must specify (process, component, interface) or (component, interface), caught exception: ' + str(e))
%}
}
%include "cisstMultiTask/mtsInterface.h"
%include "cisstMultiTask/mtsInterfaceProvided.h"
%extend mtsInterfaceProvided {
%pythoncode %{
def UpdateFromC(self):
commands = mtsInterfaceProvided.GetNamesOfCommandsVoid(self)
for command in commands:
self.__dict__[command] = mtsInterfaceProvided.GetCommandVoid(self, command)
commands = mtsInterfaceProvided.GetNamesOfCommandsVoidReturn(self)
for command in commands:
self.__dict__[command] = mtsInterfaceProvided.GetCommandVoidReturn(self, command)
self.__dict__[command].UpdateFromC()
commands = mtsInterfaceProvided.GetNamesOfCommandsWrite(self)
for command in commands:
self.__dict__[command] = mtsInterfaceProvided.GetCommandWrite(self, command)
self.__dict__[command].UpdateFromC()
commands = mtsInterfaceProvided.GetNamesOfCommandsWriteReturn(self)
for command in commands:
self.__dict__[command] = mtsInterfaceProvided.GetCommandWriteReturn(self, command)
self.__dict__[command].UpdateFromC()
commands = mtsInterfaceProvided.GetNamesOfCommandsQualifiedRead(self)
for command in commands:
self.__dict__[command] = mtsInterfaceProvided.GetCommandQualifiedRead(self, command)
self.__dict__[command].UpdateFromC()
commands = mtsInterfaceProvided.GetNamesOfCommandsRead(self)
for command in commands:
self.__dict__[command] = mtsInterfaceProvided.GetCommandRead(self, command)
self.__dict__[command].UpdateFromC()
%}
}
%include "cisstMultiTask/mtsInterfaceRequired.h"
%extend mtsInterfaceRequired {
%pythoncode %{
def UpdateFromC(self):
if not self.GetConnectedInterface():
print('Required interface ' + self.GetName() + ' not yet connected.')
return
functions = mtsInterfaceRequired.GetNamesOfFunctionsVoid(self)
for function in functions:
self.__dict__[function] = mtsInterfaceRequired.GetFunctionVoid(self, function)
functions = mtsInterfaceRequired.GetNamesOfFunctionsVoidReturn(self)
for function in functions:
self.__dict__[function] = mtsInterfaceRequired.GetFunctionVoidReturn(self, function)
self.__dict__[function].UpdateFromC()
functions = mtsInterfaceRequired.GetNamesOfFunctionsWrite(self)
for function in functions:
self.__dict__[function] = mtsInterfaceRequired.GetFunctionWrite(self, function)
self.__dict__[function].UpdateFromC()
functions = mtsInterfaceRequired.GetNamesOfFunctionsWriteReturn(self)
for function in functions:
self.__dict__[function] = mtsInterfaceRequired.GetFunctionWriteReturn(self, function)
self.__dict__[function].UpdateFromC()
functions = mtsInterfaceRequired.GetNamesOfFunctionsQualifiedRead(self)
for function in functions:
self.__dict__[function] = mtsInterfaceRequired.GetFunctionQualifiedRead(self, function)
self.__dict__[function].UpdateFromC()
functions = mtsInterfaceRequired.GetNamesOfFunctionsRead(self)
for function in functions:
self.__dict__[function] = mtsInterfaceRequired.GetFunctionRead(self, function)
self.__dict__[function].UpdateFromC()
%}
}
// Wrap manager component services (includes internal required interface)
// Typemaps below are for GetNamesOfInterfaces, so that the two vectors of strings
// (required and provided interfaces) can be returned as a list of lists of strings,
// i.e., ((req1, req2, ...),(prov1, prov2, ...))
%typemap(in, numinputs=0) std::vector<std::string> & namesOfInterfacesRequired (std::vector<std::string> temp) {
$1 = &temp;
}
%typemap(in, numinputs=0) std::vector<std::string> & namesOfInterfacesProvided (std::vector<std::string> temp) {
$1 = &temp;
}
%typemap(argout) std::vector<std::string> & namesOfInterfacesRequired {
Py_DECREF($result); // Garbage collect the returned "bool"
if (!result) {
PyErr_SetString(PyExc_RuntimeError, "Failed to get interfaces");
return NULL;
}
$result = PyTuple_New(2);
PyObject *required = PyTuple_New((*$1).size());
PyTuple_SetItem($result,0,required);
size_t i;
for (i = 0; i < (*$1).size(); i++)
PyTuple_SetItem(required,i,PyUnicode_FromString((*$1)[i].c_str()));
}
%typemap(argout) std::vector<std::string> & namesOfInterfacesProvided {
PyObject *provided = PyTuple_New((*$1).size());
PyTuple_SetItem($result,1,provided);
size_t i;
for (i = 0; i < (*$1).size(); i++)
PyTuple_SetItem(provided,i,PyUnicode_FromString((*$1)[i].c_str()));
}
%include "cisstMultiTask/mtsManagerComponentServices.h"
%include "cisstMultiTask/mtsTask.h"
%include "cisstMultiTask/mtsTaskContinuous.h"
%include "cisstMultiTask/mtsTaskPeriodic.h"
%include "cisstMultiTask/mtsTaskFromSignal.h"
%include "cisstMultiTask/mtsManagerLocal.h"
%extend mtsManagerLocal {
%pythoncode %{
def UpdateFromC(self):
comps = mtsManagerLocal.GetNamesOfComponents(self)
for comp in comps:
self.__dict__[comp] = mtsManagerLocal.GetComponent(self, comp)
self.__dict__[comp].UpdateFromC()
%}
}
%include "cisstMultiTask/mtsCollectorBase.h"
%include "cisstMultiTask/mtsCollectorState.h"
// Wrap some basic types
%include "cisstMultiTask/mtsGenericObjectProxy.h"
%define MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(name, elementType)
// ignore the operator &
%ignore mtsGenericObjectProxy<elementType>::operator value_type&;
%ignore mtsGenericObjectProxy<elementType>::operator const value_type&;
// Instantiate the template
%template(name ## Base) mtsGenericObjectProxyBase<elementType>;
%template(name) mtsGenericObjectProxy<elementType>;
// Type addition for dynamic type checking
%{
typedef mtsGenericObjectProxy<elementType> name;
%}
typedef mtsGenericObjectProxy<elementType> name;
%types(name *);
%extend mtsGenericObjectProxy<elementType> {
elementType GetDataCopy() const
{ return static_cast<elementType>($self->GetData()); }
}
%enddef
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsDouble, double);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsFloat, float);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsInt, int);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsUInt, unsigned int);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsShort, short);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsUShort, unsigned short);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsChar, char);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsUChar, unsigned char);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsLong, long);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsULong, unsigned long);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsBool, bool);
#ifdef SWIG_WINDOWS
%apply long long {size_t};
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsSizeT, size_t);
#endif
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsStdString, std::string);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsStdStringVecProxy, stdStringVec);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsStdDoubleVecProxy, stdDoubleVec);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsStdCharVecProxy, stdCharVec);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVct1, vct1);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVct2, vct2);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVct3, vct3);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVct4, vct4);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVct5, vct5);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVct6, vct6);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVct7, vct7);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVct8, vct8);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVct9, vct9);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctFloat1, vctFloat1);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctFloat2, vctFloat2);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctFloat3, vctFloat3);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctFloat4, vctFloat4);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctFloat5, vctFloat5);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctFloat6, vctFloat6);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctFloat7, vctFloat7);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctFloat8, vctFloat8);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctFloat9, vctFloat9);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctLong1, vctLong1);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctLong2, vctLong2);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctLong3, vctLong3);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctLong4, vctLong4);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctLong5, vctLong5);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctLong6, vctLong6);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctLong7, vctLong7);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctLong8, vctLong8);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctLong9, vctLong9);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctULong1, vctULong1);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctULong2, vctULong2);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctULong3, vctULong3);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctULong4, vctULong4);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctULong5, vctULong5);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctULong6, vctULong6);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctULong7, vctULong7);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctULong8, vctULong8);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctULong9, vctULong9);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctInt1, vctInt1);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctInt2, vctInt2);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctInt3, vctInt3);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctInt4, vctInt4);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctInt5, vctInt5);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctInt6, vctInt6);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctInt7, vctInt7);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctInt8, vctInt8);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctInt9, vctInt9);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctUInt1, vctUInt1);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctUInt2, vctUInt2);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctUInt3, vctUInt3);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctUInt4, vctUInt4);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctUInt5, vctUInt5);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctUInt6, vctUInt6);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctUInt7, vctUInt7);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctUInt8, vctUInt8);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctUInt9, vctUInt9);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctShort1, vctShort1);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctShort2, vctShort2);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctShort3, vctShort3);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctShort4, vctShort4);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctShort5, vctShort5);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctShort6, vctShort6);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctShort7, vctShort7);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctShort8, vctShort8);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctShort9, vctShort9);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctUShort1, vctUShort1);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctUShort2, vctUShort2);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctUShort3, vctUShort3);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctUShort4, vctUShort4);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctUShort5, vctUShort5);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctUShort6, vctUShort6);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctUShort7, vctUShort7);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctUShort8, vctUShort8);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctUShort9, vctUShort9);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctChar1, vctChar1);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctChar2, vctChar2);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctChar3, vctChar3);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctChar4, vctChar4);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctChar5, vctChar5);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctChar6, vctChar6);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctChar7, vctChar7);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctChar8, vctChar8);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctChar9, vctChar9);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctUChar1, vctUChar1);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctUChar2, vctUChar2);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctUChar3, vctUChar3);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctUChar4, vctUChar4);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctUChar5, vctUChar5);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctUChar6, vctUChar6);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctUChar7, vctUChar7);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctUChar8, vctUChar8);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctUChar9, vctUChar9);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctBool1, vctBool1);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctBool2, vctBool2);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctBool3, vctBool3);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctBool4, vctBool4);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctBool5, vctBool5);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctBool6, vctBool6);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctBool7, vctBool7);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctBool8, vctBool8);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctBool9, vctBool9);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVct2x2, vct2x2);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVct3x3, vct3x3);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVct4x4, vct4x4);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctMatRot3, vctMatRot3);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctFrm3, vctFrm3);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctFrm4x4, vctFrm4x4);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctDoubleVec, vctDoubleVec);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctFloatVec, vctFloatVec);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctIntVec, vctIntVec);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctUIntVec, vctUIntVec);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctCharVec, vctCharVec);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctUCharVec, vctUCharVec);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctBoolVec, vctBoolVec);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctShortVec, vctShortVec);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctUShortVec, vctUShortVec);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctLongVec, vctLongVec);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctULongVec, vctULongVec);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctDoubleMat, vctDoubleMat);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctFloatMat, vctFloatMat);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsVctIntMat, vctIntMat);
// Extend mtsGenericObjectProxy<vctMatRot3> to support construction from numpy array (using cisstVector
// typemaps that convert between numpy array and vctDynamicMatrix). This enables vctMatRot3 to be used
// as a parameter in cisstMultiTask commands (e.g., mtsCommandWrite).
// Note that it is not necessary for Python to know about the vctMatRot3 data type, but this could be
// implemented by adding Swig wrapping of this type in cisstVector.
%extend mtsGenericObjectProxy<vctMatRot3> {
mtsGenericObjectProxy<vctMatRot3>(const vctDynamicMatrix<double> &matrixRot) throw(std::runtime_error) {
if ((matrixRot.rows() != 3) || (matrixRot.cols() != 3))
cmnThrow(std::runtime_error("mtsGenericObjectProxy<vctMatRot3>: Input is not 3x3 matrix"));
vctMatRot3 rot;
rot.From(matrixRot[0][0], matrixRot[0][1], matrixRot[0][2],
matrixRot[1][0], matrixRot[1][1], matrixRot[1][2],
matrixRot[2][0], matrixRot[2][1], matrixRot[2][2]);
mtsGenericObjectProxy<vctMatRot3> * result = new mtsGenericObjectProxy<vctMatRot3>(rot);
return result;
}
}
%include "cisstMultiTask/mtsParameterTypes.h"
%template(mtsDescriptionConnectionVec) std::vector<mtsDescriptionConnection>;
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsDescriptionConnectionVecProxy, mtsDescriptionConnectionVec);
%template(mtsDescriptionComponentClassVec) std::vector<mtsDescriptionComponentClass>;
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsDescriptionComponentClassVecProxy, mtsDescriptionComponentClassVec);
%include "cisstMultiTask/mtsComponentState.h"
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsComponentStateProxy, mtsComponentState);
%include "cisstMultiTask/mtsInterfaceCommon.h"
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsInterfaceProvidedDescriptionProxy, mtsInterfaceProvidedDescription);
MTS_GENERIC_OBJECT_PROXY_INSTANTIATE(mtsInterfaceRequiredDescriptionProxy, mtsInterfaceRequiredDescription);
%template(mtsCommandsVoidDescription) std::vector<mtsCommandVoidDescription>;
%template(mtsCommandsVoidReturnDescription) std::vector<mtsCommandVoidReturnDescription>;
%template(mtsCommandsWriteDescription) std::vector<mtsCommandWriteDescription>;
%template(mtsCommandsWriteReturnDescription) std::vector<mtsCommandWriteReturnDescription>;
%template(mtsCommandsReadDescription) std::vector<mtsCommandReadDescription>;
%template(mtsCommandsQualifiedReadDescription) std::vector<mtsCommandQualifiedReadDescription>;
%template(mtsEventsVoidDescription) std::vector<mtsEventVoidDescription>;
%template(mtsEventsWriteDescription) std::vector<mtsEventWriteDescription>;
// Wrap mtsVector
%import "cisstMultiTask/mtsVector.h"
// define macro
%define MTS_INSTANTIATE_VECTOR(name, elementType)
// suppress warning about base class not known
%warnfilter(401) mtsVector<elementType>;
// force instantiation and define name for SWIG
%template(name) mtsVector<elementType>;
%{
typedef mtsVector<elementType> name;
%}
typedef mtsVector<elementType> name;
%types(name *);
// add two methods to retrieve the vector
%extend mtsVector<elementType>{
inline VectorType & Data(void) {
return *self;
}
inline const VectorType & Data(void) const {
return *self;
}
}
%enddef
// instantiate for types also instantiated in cisstVector wrappers
MTS_INSTANTIATE_VECTOR(mtsDoubleVec, double);
MTS_INSTANTIATE_VECTOR(mtsFloatVec, float);
MTS_INSTANTIATE_VECTOR(mtsLongVec, long);
MTS_INSTANTIATE_VECTOR(mtsULongVec, unsigned long);
MTS_INSTANTIATE_VECTOR(mtsIntVec, int);
MTS_INSTANTIATE_VECTOR(mtsUIntVec, unsigned int);
MTS_INSTANTIATE_VECTOR(mtsShortVec, short);
MTS_INSTANTIATE_VECTOR(mtsUShortVec, unsigned short);
MTS_INSTANTIATE_VECTOR(mtsCharVec, char);
MTS_INSTANTIATE_VECTOR(mtsUCharVec, unsigned char);
MTS_INSTANTIATE_VECTOR(mtsBoolVec, bool);
MTS_INSTANTIATE_VECTOR(mtsStdStringVec, std::string);
// Wrap mtsMatrix
%import "cisstMultiTask/mtsMatrix.h"
// define macro
%define MTS_INSTANTIATE_MATRIX(name, elementType)
// suppress warning about base class not known
%warnfilter(401) mtsMatrix<elementType>;
// force instantiation and define name for SWIG
%template(name) mtsMatrix<elementType>;
%{
typedef mtsMatrix<elementType> name;
%}
typedef mtsMatrix<elementType> name;
%types(name *);
// add two methods to retrieve the matrix
%extend mtsMatrix<elementType>{
inline MatrixType & Data(void) {
return *self;
}
inline const MatrixType & Data(void) const {
return *self;
}
}
%enddef
// instantiate for types also instantiated in cisstVector wrappers
MTS_INSTANTIATE_MATRIX(mtsDoubleMat, double);
MTS_INSTANTIATE_MATRIX(mtsIntMat, int);
MTS_INSTANTIATE_MATRIX(mtsShortMat, short);
MTS_INSTANTIATE_MATRIX(mtsLongMat, long);
%import "cisstMultiTask/mtsMacros.h"
%import "cisstVector/vctTransformationTypes.h"
%include "cisstMultiTask/mtsTransformationTypes.h"
// Wrap mtsStateIndex
%ignore mtsStateIndex::operator--;
%include "cisstMultiTask/mtsStateIndex.h"
// Wrap mtsIntervalStatistics
%include "cisstMultiTask/mtsIntervalStatistics.h"
%pythoncode %{
# Define separate class so that we have more flexibility to set up namespaces.
# For example, command /one/two/three will become one.two.three.
class mtsInterfaceRequiredPython:
def __init__(self):
pass
def _add_entry(self, cmdName, cmdFunc):
# Replace dashes with underscore
cmdNameFixed = cmdName.replace('-', '_')
# Split namespaces (/)
items = cmdNameFixed.split('/')
obj = self
# Loop through any namespaces
for i in range(0, len(items)-1):
if not hasattr(obj, items[i]):
setattr(obj, items[i], mtsInterfaceRequiredPython())
obj = getattr(obj, items[i])
# Last (or only) item is set to the func
setattr(obj, items[len(items)-1], cmdFunc)
# Dynamically load and create a server component
#
# This function dynamically loads the specified library and constructs an object using the
# specified component class (className). The component name is specified through argSerialized
# (if not empty); otherwise componentName is used. Note that if argSerialized is not empty,
# componentName is ignored.
def mtsLoadAndCreateServer(libraryName, className, componentName, argSerialized):
print('Loading ' + libraryName)
import cisstOSAbstractionPython as cisstOSAbstraction
DynLoader = cisstOSAbstraction.osaDynamicLoader()
if not DynLoader.Load(libraryName):
print('Failed to load ' + libraryName + ' (see cisstLog.txt)')
return None
print('Creating ' + componentName + ' (' + className + ')')
LCM = mtsManagerLocal.GetInstance()
if (not argSerialized):
comp = LCM.CreateComponentDynamically(className, componentName, '')
else:
comp = LCM.CreateComponentDynamically(className, argSerialized)
if comp:
print('Component created')
LCM.AddComponent(comp)
return comp
# Create client component (if necessary) and then create required interface to server
# provided interface
def mtsCreateClientInterface(clientName, serverName, interfaceName):
LCM = mtsManagerLocal.GetInstance()
if (LCM.FindComponent(clientName)):
print('mtsCreateClientInterface: component ' + clientName + ' already exists')
client = LCM.GetComponent(clientName)
else:
print('Creating ' + clientName)
client = LCM.CreateComponentDynamically('mtsComponent', clientName, '')
if not client:
print('Failed to create ' + clientName)
return None
LCM.AddComponent(client)
interface = None
if (serverName and interfaceName):
print('Connecting ' + clientName + ' to ' + serverName + ' (' + interfaceName + ')')
interface = client.AddInterfaceRequiredAndConnect((serverName, interfaceName))
interfacePython = None
if interface:
interfacePython = mtsInterfaceRequiredPython()
for name in interface.GetNamesOfFunctions():
interfacePython._add_entry(name, getattr(interface, name))
return interfacePython
%}
|