/*============================================================================= NOTE: THIS FILE IS A HANDMADE WRAPPER FOR THE ManagedITK PROJECT. Project: ManagedITK Program: Insight Segmentation & Registration Toolkit Module: itkManagedProcessObjectCommand.cxx Language: C++/CLI Author: Dan Mueller Date: $Date: 2007-09-01 06:17:25 +1000 (Sat, 01 Sep 2007) $ Revision: $Revision: 2 $ 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 __itkManagedProcessObjectCommand_cxx #define __itkManagedProcessObjectCommand_cxx // Include some useful ITK headers #pragma unmanaged #include "itkCommand.h" #include "itkEventObject.h" #include "itkProcessObject.h" // Force Managed #pragma managed // Use System namespaces #using using namespace System; // Include the auto_gcroot 'smart pointer' #include using namespace msclr; // Include ManagedITK.Common #using namespace itk { /// ///A native itk::Command which raises managed events on the internal ///managed itkProcessObject. /// private class itkProcessObjectCommand : public itk::Command { public: typedef itkProcessObjectCommand 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: itkProcessObjectCommand(){}; ~itkProcessObjectCommand(){}; 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) { // Cast caller to ProcessObject itk::ProcessObject::Pointer process = dynamic_cast(caller); // Raise the corresponding managed event if (itk::ProgressEvent().CheckEvent(&event)) this->m_PointerToManagedObject->InvokeProgressEvent(process->GetProgress()); else 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