diff --git a/Modules/Simulation/mitkSimulationWriter.cpp b/Modules/Simulation/mitkSimulationWriter.cpp index 91d8bcbf27..6794785b43 100644 --- a/Modules/Simulation/mitkSimulationWriter.cpp +++ b/Modules/Simulation/mitkSimulationWriter.cpp @@ -1,152 +1,158 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include #include #include "mitkSimulation.h" #include "mitkSimulationWriter.h" mitk::SimulationWriter::SimulationWriter() : m_FileExtension(".scn"), m_MIMEType("application/xml") { this->SetNumberOfRequiredInputs(1); this->SetNumberOfIndexedOutputs(0); } mitk::SimulationWriter::~SimulationWriter() { } void mitk::SimulationWriter::GenerateData() { if (m_FileName.empty()) mitkThrow() << "Filename is empty!"; Simulation* simulation = dynamic_cast(this->GetInput(0)); if (simulation == NULL) mitkThrow() << "Invalid input!"; std::string originalPath = "\n"; std::ofstream scnFile(m_FileName.c_str()); scnFile << originalPath << simulation->GetProperty("Scene File")->GetValueAsString(); } mitk::Simulation* mitk::SimulationWriter::GetInput() { if (this->GetNumberOfInputs() == 0) return NULL; return dynamic_cast(this->GetInput(0)); } void mitk::SimulationWriter::SetInput(Simulation *simulation) { this->SetNthInput(0, simulation); } const char* mitk::SimulationWriter::GetFileName() const { return m_FileName.c_str(); } void mitk::SimulationWriter::SetFileName(const char* fileName) { m_FileName = fileName; } const char* mitk::SimulationWriter::GetFilePrefix() const { return m_FilePrefix.c_str(); } void mitk::SimulationWriter::SetFilePrefix(const char* filePrefix) { m_FilePrefix = filePrefix; } const char* mitk::SimulationWriter::GetFilePattern() const { return m_FilePattern.c_str(); } void mitk::SimulationWriter::SetFilePattern(const char* filePattern) { m_FilePattern = filePattern; } std::string mitk::SimulationWriter::GetFileExtension() { return m_FileExtension; } std::vector mitk::SimulationWriter::GetPossibleFileExtensions() { std::vector possibleFileExtensions; possibleFileExtensions.push_back(m_FileExtension); return possibleFileExtensions; } std::string mitk::SimulationWriter::GetWritenMIMEType() { return m_MIMEType; } bool mitk::SimulationWriter::CanWriteDataType(DataNode* dataNode) { if (dataNode == NULL) return false; return this->CanWriteBaseDataType(dataNode->GetData()); } const char* mitk::SimulationWriter::GetDefaultFilename() { std::string defaultFilename = "Simulation" + m_FileExtension; return defaultFilename.c_str(); } const char* mitk::SimulationWriter::GetFileDialogPattern() { std::string fileDialogPattern = "SOFA Scene Files (*" + m_FileExtension + ")"; return fileDialogPattern.c_str(); } const char* mitk::SimulationWriter::GetDefaultExtension() { return m_FileExtension.c_str(); } bool mitk::SimulationWriter::CanWriteBaseDataType(BaseData::Pointer data) { if (data.IsNull()) return false; return dynamic_cast(data.GetPointer()) != NULL; } void mitk::SimulationWriter::DoWrite(BaseData::Pointer data) { if (this->CanWriteBaseDataType(data)) { this->SetNthInput(0, dynamic_cast(data.GetPointer())); this->Update(); } } + + +std::string mitk::SimulationWriter::GetSupportedBaseData() const +{ + return Simulation::GetStaticNameOfClass(); +} diff --git a/Modules/Simulation/mitkSimulationWriter.h b/Modules/Simulation/mitkSimulationWriter.h index b94aa4e4be..eab385e720 100644 --- a/Modules/Simulation/mitkSimulationWriter.h +++ b/Modules/Simulation/mitkSimulationWriter.h @@ -1,77 +1,79 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef mitkSimulationWriter_h #define mitkSimulationWriter_h #include #include namespace mitk { class Simulation; class MitkSimulation_EXPORT SimulationWriter : public FileWriterWithInformation { public: mitkClassMacro(SimulationWriter, FileWriterWithInformation); itkFactorylessNewMacro(Self); itkCloneMacro(Self); using Superclass::SetInput; void SetInput(Simulation* simulation); // mitk::FileWriter interface mitkWriterMacro; using Superclass::GetInput; Simulation* GetInput(); const char* GetFileName() const; void SetFileName(const char* fileName); const char* GetFilePrefix() const; void SetFilePrefix(const char* filePrefix); const char* GetFilePattern() const; void SetFilePattern(const char* filePattern); std::string GetFileExtension(); std::vector GetPossibleFileExtensions(); std::string GetWritenMIMEType(); bool CanWriteDataType(DataNode* dataNode); // mitk::FileWriterWithInformation interface const char* GetDefaultFilename(); const char* GetFileDialogPattern(); const char* GetDefaultExtension(); bool CanWriteBaseDataType(BaseData::Pointer data); void DoWrite(BaseData::Pointer data); + std::string GetSupportedBaseData() const; + protected: SimulationWriter(); ~SimulationWriter(); void GenerateData(); private: std::string m_FileName; std::string m_FilePrefix; std::string m_FilePattern; std::string m_FileExtension; std::string m_MIMEType; }; } #endif