/*============================================================================= NOTE: THIS FILE IS A HANDMADE WRAPPER FOR THE ManagedITK PROJECT. Project: ManagedITK Program: Insight Segmentation & Registration Toolkit Module: itkManagedObjectCommand.cxx Language: C++/CLI Author: Dan Mueller $Date: 2007-04-11 16:26:16 +1000 (Wed, 11 Apr 2007) $ $Revision: 128 $ Copyright (c) Queensland University of Technology (QUT) 2007. All rights reserved. Portions of this code are covered under the ITK and VTK copyright. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =============================================================================*/ #pragma once #pragma warning( disable : 4635 ) // Disable warnings about XML doc comments #ifndef __itkManagedObjectCommand_cxx #define __itkManagedObjectCommand_cxx // Include some useful ITK headers #pragma unmanaged #include "itkCommand.h" #include "itkEventObject.h" #include "itkObject.h" // Force Managed #pragma managed // Use System namespaces #using using namespace System; // Include the auto_gcroot 'smart pointer' #include using namespace msclr; #ifdef IncludeObjectCommandFromSource #include "itkManagedObject.cxx" #else #using #endif namespace itk { /// ///A native itk::Command which raises managed events on the internal ///managed itkObject. /// private class itkObjectCommand : public itk::Command { public: typedef itkObjectCommand Self; typedef itk::Command Superclass; typedef itk::SmartPointer Pointer; itkNewMacro( Self ); // Create a useful typedef for the managed object pointer // NOTE: This is NOT auto_gcroot because we don't want to // release the managed object when the Command // pointer is removed and/or goes out of scope. typedef gcroot PointerToManagedObjectType; protected: itkObjectCommand(){}; ~itkObjectCommand(){}; private: PointerToManagedObjectType m_PointerToManagedObject; public: /** Method: Set the managed object for which the events should be * passed along to. */ void SetManagedObject(PointerToManagedObjectType ptrManagedObject) { this->m_PointerToManagedObject = ptrManagedObject; } /** Called when the native ITK event is raised. */ void Execute(itk::Object *caller, const itk::EventObject & event) { // Raise the corresponding managed event if (itk::StartEvent().CheckEvent(&event)) this->m_PointerToManagedObject->InvokeStartedEvent( DateTime::Now ); else if (itk::EndEvent().CheckEvent(&event)) this->m_PointerToManagedObject->InvokeEndedEvent( DateTime::Now ); else if (itk::AbortEvent().CheckEvent(&event)) this->m_PointerToManagedObject->InvokeAbortedEvent( DateTime::Now ); else if (itk::IterationEvent().CheckEvent(&event)) this->m_PointerToManagedObject->InvokeIterationEvent(); else if (itk::ModifiedEvent().CheckEvent(&event)) this->m_PointerToManagedObject->InvokeModifiedEvent(); } void Execute(const itk::Object *caller, const itk::EventObject & event) { return; } }; } // end namespace itk #endif