ctkVTKObjectEventsObserver.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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 __ctkVTKObjectEventsObserver_h
  15. #define __ctkVTKObjectEventsObserver_h
  16. /// Qt includes
  17. #include <QObject>
  18. #include <QList>
  19. #include <QString>
  20. /// CTK includes
  21. #include <ctkSingleton.h>
  22. #include "ctkVisualizationVTKCoreExport.h"
  23. class ctkVTKConnection;
  24. class ctkVTKObjectEventsObserverPrivate;
  25. /// VTK includes
  26. #include <vtkCommand.h>
  27. class vtkObject;
  28. //-----------------------------------------------------------------------------
  29. /// \ingroup Visualization_VTK_Core
  30. class CTK_VISUALIZATION_VTK_CORE_EXPORT ctkVTKObjectEventsObserver : public QObject
  31. {
  32. Q_OBJECT
  33. Q_PROPERTY(bool strictTypeCheck READ strictTypeCheck WRITE setStrictTypeCheck)
  34. public:
  35. typedef QObject Superclass;
  36. explicit ctkVTKObjectEventsObserver(QObject* parent = 0);
  37. virtual ~ctkVTKObjectEventsObserver();
  38. virtual void printAdditionalInfo();
  39. /// The property strictTypeCheck control wether or not you can replace a
  40. /// connection by a connection from an object of a different VTK class tha
  41. /// the first.
  42. /// For example, if strictTypeCheck is on, the following will generate an error
  43. /// <code>
  44. /// vtkActor* actor = vtkActor::New();
  45. /// objectEventsObserver->addConnection(actor, vtkCommand::ModifiedEvent, ...);
  46. /// vtkMapper* mapper = vtkMapper::New();
  47. /// objectEventsObserver->addConnection(actor, mapper, vtkCommand::ModifiedEvent, ...);
  48. /// </code>
  49. /// False by default.
  50. bool strictTypeCheck()const;
  51. void setStrictTypeCheck(bool check);
  52. ///
  53. /// Add a connection, an Id allowing to uniquely identify the connection is
  54. /// returned. It is a no-op if vtk_obj is NULL, the parameters are invalid or
  55. /// if the connection already exist.
  56. /// Warning the slot must have its signature order:
  57. /// vtkObject*, vtkObject* : sender, callData
  58. /// or
  59. /// vtkObject*, void*, unsigned long, void*: sender, callData, eventId, clientData
  60. /// Of course the slot can contain less parameters, but always the same order
  61. /// though.
  62. QString addConnection(vtkObject* vtk_obj, unsigned long vtk_event,
  63. const QObject* qt_obj, const char* qt_slot, float priority = 0.0,
  64. Qt::ConnectionType connectionType = Qt::AutoConnection);
  65. ///
  66. /// Utility function that remove a connection on old_vtk_obj and add a connection
  67. /// to vtk_obj (same event, object, slot, priority)
  68. /// Warning the slot must have its signature order:
  69. /// vtkObject*, vtkObject* : sender, callData
  70. /// or
  71. /// vtkObject*, void*, unsigned long, void*: sender, callData, eventId, clientData
  72. /// Of course the slot can contain less parameters, but always the same order
  73. /// though.
  74. QString addConnection(vtkObject* old_vtk_obj, vtkObject* vtk_obj, unsigned long vtk_event,
  75. const QObject* qt_obj, const char* qt_slot, float priority = 0.0,
  76. Qt::ConnectionType connectionType = Qt::AutoConnection);
  77. ///
  78. /// Utility function that remove a connection on old_vtk_obj and add a connection
  79. /// to vtk_obj (same event, object, slot, priority)
  80. /// Warning the slot must have its signature order:
  81. /// vtkObject*, vtkObject* : sender, callData
  82. /// or
  83. /// vtkObject*, void*, unsigned long, void*: sender, callData, eventId, clientData
  84. /// Of course the slot can contain less parameters, but always the same order
  85. /// though.
  86. QString reconnection(vtkObject* vtk_obj, unsigned long vtk_event,
  87. const QObject* qt_obj, const char* qt_slot,
  88. float priority = 0.0,
  89. Qt::ConnectionType connectionType = Qt::AutoConnection);
  90. ///
  91. /// Remove all the connections matching vtkobj, event, qtobj and slot using
  92. /// wildcards or not.
  93. /// Returns the number of connection removed.
  94. int removeConnection(vtkObject* vtk_obj, unsigned long vtk_event = vtkCommand::NoEvent,
  95. const QObject* qt_obj = 0, const char* qt_slot = 0);
  96. ///
  97. /// Remove all the connections
  98. int removeAllConnections();
  99. ///
  100. /// Temporarilly block all the connection
  101. /// Returns the previous value of connectionsBlocked()
  102. bool blockAllConnections(bool block);
  103. ///
  104. /// Returns true if connections are blocked; otherwise returns false.
  105. /// Connections are not blocked by default.
  106. bool connectionsBlocked()const;
  107. ///
  108. /// Block/Unblock one or multiple connection.
  109. /// Return the number of connections blocked/unblocked
  110. int blockConnection(bool block, vtkObject* vtk_obj,
  111. unsigned long vtk_event, const QObject* qt_obj);
  112. /// Block/Unblock a connection
  113. /// Return true if the connection exists and was blocked, otherwise returns
  114. /// false.
  115. bool blockConnection(const QString& id, bool blocked);
  116. /// Return true if there is at least 1 connection matching the parameters,
  117. /// false otherwise.
  118. bool containsConnection(vtkObject* vtk_obj, unsigned long vtk_event = vtkCommand::NoEvent,
  119. const QObject* qt_obj =0, const char* qt_slot =0)const;
  120. protected:
  121. QScopedPointer<ctkVTKObjectEventsObserverPrivate> d_ptr;
  122. private:
  123. Q_DECLARE_PRIVATE(ctkVTKObjectEventsObserver);
  124. Q_DISABLE_COPY(ctkVTKObjectEventsObserver);
  125. };
  126. //-----------------------------------------------------------------------------
  127. /// \ingroup Visualization_VTK_Core
  128. class CTK_VISUALIZATION_VTK_CORE_EXPORT ctkVTKConnectionFactory
  129. {
  130. public:
  131. static ctkVTKConnectionFactory* instance();
  132. /// The singleton takes ownerchip of the new factory instance and will take care
  133. /// of cleaning the memory.
  134. /// \note If \a newInstance is not null, the current factory instance will be
  135. /// deleted. Note also that setting a null \a newInstance is a no-op.
  136. static void setInstance(ctkVTKConnectionFactory* newInstance);
  137. virtual ctkVTKConnection* createConnection(ctkVTKObjectEventsObserver*)const;
  138. protected:
  139. ctkVTKConnectionFactory();
  140. virtual ~ctkVTKConnectionFactory();
  141. CTK_SINGLETON_DECLARE(ctkVTKConnectionFactory)
  142. };
  143. CTK_SINGLETON_DECLARE_INITIALIZER(CTK_VISUALIZATION_VTK_CORE_EXPORT, ctkVTKConnectionFactory)
  144. #endif