ctkVTKObjectEventsObserver.h 6.7 KB

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