ctkVTKObjectEventsObserver.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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.commontk.org/LICENSE
  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. ///
  63. /// Utility function that remove a connection on old_vtk_obj and add a connection
  64. /// to vtk_obj (same event, object, slot, priority)
  65. /// Warning the slot must have its signature order:
  66. /// vtkObject*, vtkObject* : sender, callData
  67. /// or
  68. /// vtkObject*, void*, unsigned long, void*: sender, callData, eventId, clientData
  69. /// Of course the slot can contain less parameters, but always the same order
  70. /// though.
  71. QString addConnection(vtkObject* old_vtk_obj, vtkObject* vtk_obj, unsigned long vtk_event,
  72. const QObject* qt_obj, const char* qt_slot, float priority = 0.0);
  73. ///
  74. /// Utility function that remove a connection on old_vtk_obj and add a connection
  75. /// to vtk_obj (same event, object, slot, priority)
  76. /// Warning the slot must have its signature order:
  77. /// vtkObject*, vtkObject* : sender, callData
  78. /// or
  79. /// vtkObject*, void*, unsigned long, void*: sender, callData, eventId, clientData
  80. /// Of course the slot can contain less parameters, but always the same order
  81. /// though.
  82. QString reconnection(vtkObject* vtk_obj, unsigned long vtk_event,
  83. const QObject* qt_obj, const char* qt_slot,
  84. float priority = 0.0);
  85. ///
  86. /// Remove all the connections matching vtkobj, event, qtobj and slot using
  87. /// wildcards or not.
  88. /// Returns the number of connection removed.
  89. int removeConnection(vtkObject* vtk_obj, unsigned long vtk_event = vtkCommand::NoEvent,
  90. const QObject* qt_obj = 0, const char* qt_slot = 0);
  91. ///
  92. /// Remove all the connections
  93. inline int removeAllConnections();
  94. ///
  95. /// Temporarilly block all the connection
  96. /// Returns the previous value of connectionsBlocked()
  97. bool blockAllConnections(bool block);
  98. ///
  99. /// Returns true if connections are blocked; otherwise returns false.
  100. /// Connections are not blocked by default.
  101. bool connectionsBlocked()const;
  102. ///
  103. /// Block/Unblock one or multiple connection.
  104. /// Return the number of connections blocked/unblocked
  105. int blockConnection(bool block, vtkObject* vtk_obj,
  106. unsigned long vtk_event, const QObject* qt_obj);
  107. /// Block/Unblock a connection
  108. /// Return true if the connection exists and was blocked, otherwise returns
  109. /// false.
  110. bool blockConnection(const QString& id, bool blocked);
  111. /// Return true if there is at least 1 connection that match the parameter
  112. bool containsConnection(vtkObject* vtk_obj, unsigned long vtk_event = vtkCommand::NoEvent,
  113. const QObject* qt_obj =0, const char* qt_slot =0)const;
  114. //-----------------------------------------------------------------------------
  115. class CTK_VISUALIZATION_VTK_CORE_EXPORT ctkVTKConnectionFactory
  116. {
  117. public:
  118. virtual ctkVTKConnection* createConnection(ctkVTKObjectEventsObserver*)const;
  119. };
  120. static ctkVTKConnectionFactory* connectionFactory;
  121. protected:
  122. QScopedPointer<ctkVTKObjectEventsObserverPrivate> d_ptr;
  123. private:
  124. Q_DECLARE_PRIVATE(ctkVTKObjectEventsObserver);
  125. Q_DISABLE_COPY(ctkVTKObjectEventsObserver);
  126. };
  127. //-----------------------------------------------------------------------------
  128. int ctkVTKObjectEventsObserver::removeAllConnections()
  129. {
  130. return this->removeConnection(0, vtkCommand::NoEvent, 0, 0);
  131. }
  132. #endif