KWWidgets
|
00001 /*========================================================================= 00002 00003 Module: $RCSfile: vtkKWObject.h,v $ 00004 00005 Copyright (c) Kitware, Inc. 00006 All rights reserved. 00007 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 00008 00009 This software is distributed WITHOUT ANY WARRANTY; without even 00010 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00011 PURPOSE. See the above copyright notice for more information. 00012 00013 =========================================================================*/ 00014 // .NAME vtkKWObject - Superclass that supports basic Tcl functionality 00015 // .SECTION Description 00016 // vtkKWObject is the superclass for most application classes. 00017 // It is a direct subclass of vtkObject but adds functionality for 00018 // invoking Tcl scripts, obtaining the Tcl name for an instance, etc. 00019 // This class requires a vtkKWApplication in order to work (as do all classes). 00020 // .SECTION See Also 00021 // vtkKWApplication 00022 00023 #ifndef __vtkKWObject_h 00024 #define __vtkKWObject_h 00025 00026 #include "vtkObject.h" 00027 00028 #include "vtkTcl.h" // Needed for Tcl interpreter 00029 #include "vtkKWWidgets.h" // Needed for export symbols directives 00030 00031 class vtkKWApplication; 00032 class vtkCallbackCommand; 00033 00034 class KWWidgets_EXPORT vtkKWObject : public vtkObject 00035 { 00036 public: 00037 static vtkKWObject* New(); 00038 vtkTypeRevisionMacro(vtkKWObject,vtkObject); 00039 void PrintSelf(ostream& os, vtkIndent indent); 00040 00041 // Description: 00042 // Get the name of the Tcl object this instance represents. 00043 const char *GetTclName(); 00044 00045 // Description: 00046 // Set/Get the application instance for this object. 00047 vtkGetObjectMacro(Application,vtkKWApplication); 00048 virtual void SetApplication (vtkKWApplication* arg); 00049 00050 //BTX 00051 // Description: 00052 // Invoke some Tcl script code and perform argument substitution. 00053 virtual const char* Script(const char *EventString, ...); 00054 //ETX 00055 00056 // Description: 00057 // Add/Remove a callback command observer. 00058 // This AddCallbackCommandObserver() method makes sure the 00059 // CallbackCommand object is setup properly, then add an observer on 00060 // 'object', if it does not exist already. This observer is triggered by 00061 // 'event' and will invoke the CallbackCommand's Execute() method. 00062 // This method is prefered over the vtkObject::AddObserver method as 00063 // it takes care of initializing CallbackCommand, and eventually keep 00064 // track of observers that have been added, so that they can be removed 00065 // properly using RemoveCallbackCommandObserver(s). 00066 // Listeners (i.e. classes that add observers) can process the events 00067 // sent by the object/observer pairs by re-implementing the protected 00068 // ProcessCallbackCommandEvents virtual method. 00069 virtual void AddCallbackCommandObserver( 00070 vtkObject *object, unsigned long event); 00071 virtual void RemoveCallbackCommandObserver( 00072 vtkObject *object, unsigned long event); 00073 00074 // Description: 00075 // Add all the default observers needed by that object, or remove 00076 // all the observers that were added through AddCallbackCommandObservers. 00077 // Subclasses can override these methods to add/remove their own default 00078 // observers, but should call the superclass too. 00079 // Note that RemoveCallbackCommandObservers should not remove *all* the 00080 // observers that were added using AddCallbackCommandObserver, but only 00081 // the ones that were added in AddCallbackCommandObservers (i.e. they 00082 // are symmetrical methods). 00083 virtual void AddCallbackCommandObservers() {}; 00084 virtual void RemoveCallbackCommandObservers(); 00085 00086 protected: 00087 vtkKWObject(); 00088 ~vtkKWObject(); 00089 00090 // Description: 00091 // Convenience method that can be used to create a Tcl callback command. 00092 // The 'command' argument is a pointer to the command to be created. 00093 // The 'object' argument is the object that will have the method called on 00094 // it. The 'method' argument is the name of the method to be called and any 00095 // arguments in string form. If the object is NULL, the method is still 00096 // evaluated as a simple command. 00097 // Note that 'command' is allocated automatically using the 'new' 00098 // operator. If it is not NULL, it is deallocated first using 'delete []'. 00099 virtual void SetObjectMethodCommand( 00100 char **command, vtkObject *object, const char *method); 00101 00102 // Description: 00103 // Convenience method to invoke a Tcl callback command that was created 00104 // using the SetObjectMethodCommand method. This simply checks if the 00105 // command is not empty and evaluate it from Tcl. 00106 virtual void InvokeObjectMethodCommand(const char *command); 00107 00108 // Description: 00109 // Get the callback command. 00110 // Its ClientData is set to this vtkKWObject instance 00111 // itself, do not change it. Its Execute() method calls the static 00112 // ProcessCallbackCommandEventsFunction method, passing it its ClientData, 00113 // which in turn is converted back to a vtkKWObject pointer. The virtual 00114 // ProcessCallbackCommandEvents method is invokved on that pointer. 00115 // Subclasses can override this method to set specific flags, like 00116 // the AbortFlagOnExecute flag. 00117 virtual vtkCallbackCommand* GetCallbackCommand(); 00118 00119 // Description: 00120 // Processes the events that are passed through CallbackCommand (or others). 00121 // Subclasses can override this method to process their own events, but 00122 // should call the superclass too. 00123 // Also check AddCallbackCommandObserver and RemoveCallbackCommandObserver. 00124 virtual void ProcessCallbackCommandEvents( 00125 vtkObject *caller, unsigned long event, void *calldata); 00126 00127 // Description: 00128 // Static callback function that is invoked by the 00129 // CallbackCommand's Execute() method. It converts its clientdata back to 00130 // a vtkKWObject pointer and invoke its virtual 00131 // ProcessCallbackCommandEvents method. Subclass should *not* reimplement 00132 // this method, but the virtual ProcessCallbackCommandEvents instead. 00133 static void ProcessCallbackCommandEventsFunction( 00134 vtkObject *object, unsigned long event, void *clientdata, void *calldata); 00135 00136 private: 00137 00138 vtkKWApplication *Application; 00139 char *TclName; 00140 00141 // Description: 00142 // The callback command. In private, so that GetCallbackCommand() can be 00143 // used to lazy allocate it. 00144 vtkCallbackCommand *CallbackCommand; 00145 00146 vtkKWObject(const vtkKWObject&); // Not implemented 00147 void operator=(const vtkKWObject&); // Not implemented 00148 }; 00149 00150 #endif 00151