ctkCorePythonQtDecorators.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0.txt
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. =========================================================================*/
  14. #ifndef __ctkCorePythonQtDecorators_h
  15. #define __ctkCorePythonQtDecorators_h
  16. // PythonQt includes
  17. #include <PythonQt.h>
  18. // CTK includes
  19. #include <ctkErrorLogModel.h>
  20. #include <ctkWorkflowStep.h>
  21. #include <ctkWorkflowTransitions.h>
  22. // NOTE:
  23. //
  24. // For decorators it is assumed that the methods will never be called
  25. // with the self argument as NULL. The self argument is the first argument
  26. // for non-static methods.
  27. //
  28. /// \ingroup Core
  29. class ctkCorePythonQtDecorators : public QObject
  30. {
  31. Q_OBJECT
  32. public:
  33. ctkCorePythonQtDecorators()
  34. {
  35. PythonQt::self()->registerCPPClass("ctkWorkflowStep", 0, "CTKCore");
  36. PythonQt::self()->registerClass(&ctkWorkflowInterstepTransition::staticMetaObject, "CTKCore");
  37. }
  38. public Q_SLOTS:
  39. //
  40. // ctkWorkflowStep
  41. //
  42. ctkWorkflowStep* new_ctkWorkflowStep()
  43. {
  44. return new ctkWorkflowStep();
  45. }
  46. ctkWorkflowStep* new_ctkWorkflowStep(const QString& newId)
  47. {
  48. return new ctkWorkflowStep(newId);
  49. }
  50. void delete_ctkWorkflowStep(ctkWorkflowStep * step)
  51. {
  52. delete step;
  53. }
  54. ctkWorkflow* workflow(ctkWorkflowStep* step)const
  55. {
  56. return step->workflow();
  57. }
  58. QString id(ctkWorkflowStep* step)const
  59. {
  60. return step->id();
  61. }
  62. void setId(ctkWorkflowStep* step, const QString& newId)const
  63. {
  64. step->setId(newId);
  65. }
  66. QString name(ctkWorkflowStep* step)const
  67. {
  68. return step->name();
  69. }
  70. void setName(ctkWorkflowStep* step, const QString& newName)
  71. {
  72. step->setName(newName);
  73. }
  74. QString description(ctkWorkflowStep* step)const
  75. {
  76. return step->description();
  77. }
  78. void setDescription(ctkWorkflowStep* step, const QString& newDescription)
  79. {
  80. step->setDescription(newDescription);
  81. }
  82. QString statusText(ctkWorkflowStep* step)const
  83. {
  84. return step->statusText();
  85. }
  86. bool hasValidateCommand(ctkWorkflowStep* step)const
  87. {
  88. return step->hasValidateCommand();
  89. }
  90. void setHasValidateCommand(ctkWorkflowStep* step, bool newHasValidateCommand)
  91. {
  92. step->setHasValidateCommand(newHasValidateCommand);
  93. }
  94. bool hasOnEntryCommand(ctkWorkflowStep* step)const
  95. {
  96. return step->hasOnEntryCommand();
  97. }
  98. void setHasOnEntryCommand(ctkWorkflowStep* step, bool newHasOnEntryCommand)
  99. {
  100. step->setHasOnEntryCommand(newHasOnEntryCommand);
  101. }
  102. bool hasOnExitCommand(ctkWorkflowStep* step)const
  103. {
  104. return step->hasOnExitCommand();
  105. }
  106. void setHasOnExitCommand(ctkWorkflowStep* step, bool newHasOnExitCommand)
  107. {
  108. step->setHasOnExitCommand(newHasOnExitCommand);
  109. }
  110. QObject* ctkWorkflowStepQObject(ctkWorkflowStep* step)
  111. {
  112. return step->ctkWorkflowStepQObject();
  113. }
  114. //
  115. // ctkWorkflowInterstepTransition
  116. //
  117. ctkWorkflowInterstepTransition* new_ctkWorkflowInterstepTransition(ctkWorkflowInterstepTransition::InterstepTransitionType newTransitionType)
  118. {
  119. return new ctkWorkflowInterstepTransition(newTransitionType);
  120. }
  121. ctkWorkflowInterstepTransition* new_ctkWorkflowInterstepTransition(ctkWorkflowInterstepTransition::InterstepTransitionType newTransitionType, const QString& newId)
  122. {
  123. return new ctkWorkflowInterstepTransition(newTransitionType, newId);
  124. }
  125. void delete_ctkWorkflowInterstepTransition(ctkWorkflowInterstepTransition * transition)
  126. {
  127. delete transition;
  128. }
  129. // ctkErrorLogLevel
  130. QString static_ctkErrorLogLevel_logLevelAsString(ctkErrorLogLevel::LogLevel logLevel)
  131. {
  132. return ctkErrorLogLevel::logLevelAsString(logLevel);
  133. }
  134. };
  135. //-----------------------------------------------------------------------------
  136. void initCTKCorePythonQtDecorators()
  137. {
  138. // HACK: Since the CMake based light wrapping only consider class name matching the
  139. // filename where the class is defined, let's explicitly register ctkErrorLogLevel
  140. // so that the log level QFlags are exposed to python.
  141. PythonQt::self()->registerClass(&ctkErrorLogLevel::staticMetaObject, "CTKCore");
  142. PythonQt::self()->addDecorators(new ctkCorePythonQtDecorators);
  143. }
  144. #endif