ctkVTKObjectEventsObserver.h 6.8 KB

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