ctkVTKObjectEventsObserver.h 6.6 KB

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