ctkVTKObjectEventsObserver.h 6.1 KB

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