23 #include <sofa/helper/system/SetDirectory.h>
48 sofa::simulation::Simulation::SPtr sofaSimulation = simulation->GetSOFASimulation();
55 std::ifstream scnFile(this->GetLocalFileName().c_str());
56 std::string content = std::string((std::istreambuf_iterator<char>(scnFile)), std::istreambuf_iterator<char>());
59 std::istringstream stream(content);
60 std::string firstLine;
62 if (!std::getline(stream, firstLine).good())
63 mitkThrow() <<
"Could not load '" << this->GetLocalFileName() <<
"'!";
65 std::string originalPath;
67 if (firstLine.size() > 21 && firstLine.substr(0, 21) ==
"<!-- ORIGINAL_PATH = ")
69 originalPath = firstLine.substr(21);
70 sofa::helper::system::DataRepository.addFirstPath(originalPath);
73 std::string path = sofa::helper::system::SetDirectory::GetParentDir(this->GetLocalFileName().c_str());
74 sofa::helper::system::DataRepository.addFirstPath(path);
76 sofa::simulation::Node::SPtr rootNode = sofa::core::objectmodel::SPtr_dynamic_cast<sofa::simulation::Node>(sofaSimulation->load(this->GetLocalFileName().c_str()));
80 sofa::helper::system::DataRepository.removePath(path);
81 mitkThrow() <<
"Could not load '" << this->GetLocalFileName() <<
"'!";
84 simulation->SetRootNode(rootNode);
86 sofaSimulation->init(rootNode.get());
87 sofaSimulation->reset(rootNode.get());
88 simulation->UpdateOutputInformation();
90 sofa::helper::system::DataRepository.removePath(path);
92 if (!originalPath.empty())
94 sofa::helper::system::DataRepository.removePath(originalPath);
106 std::vector<BaseData::Pointer> returnValue;
107 returnValue.push_back(simulation.GetPointer());
117 std::string inputLocation = this->GetInputLocation();
118 std::string::size_type length = inputLocation.length();
123 std::string ext = inputLocation.substr(length - 4);
124 std::transform(ext.begin(), ext.end(), ext.begin(), tolower);
126 return ext !=
".scn" && ext !=
".xml"
133 this->ValidateOutputLocation();
137 if (simulation == NULL)
140 std::string originalContent = simulation->
GetProperty(
"Scene File")->GetValueAsString();
143 std::ofstream scnFile(localFile.
GetFileName().c_str());
145 if (originalContent.size() < 22 || originalContent.substr(0, 21) !=
"<!-- ORIGINAL_PATH = ")
147 std::string originalPath =
"<!-- ORIGINAL_PATH = ";
148 originalPath += simulation->
GetProperty(
"Path")->GetValueAsString();
149 originalPath +=
"\n This comment is parsed by MITK. -->\n";
151 scnFile << originalPath;
154 scnFile << originalContent;
162 return dynamic_cast<const Simulation*
>(this->GetInput()) == NULL
std::vector< BaseData::Pointer > Read() override
Reads a path or stream and creates a list of BaseData objects.
virtual ConfidenceLevel GetReaderConfidenceLevel() const override
std::string GetFileName()
void SetComment(const std::string &comment)
ConfidenceLevel GetWriterConfidenceLevel() const override
The CustomMimeType class represents a custom mime-type which may be registered as a service object...
static std::string DEFAULT_BASE_NAME()
std::pair< us::ServiceRegistration< IFileReader >, us::ServiceRegistration< IFileWriter > > RegisterService(us::ModuleContext *context=us::GetModuleContext())
MITKSIMULATION_EXPORT ISimulationService * GetSimulationService(us::ModuleContext *moduleContext=us::GetModuleContext())
static const char * GetStaticNameOfClass()
ConfidenceLevel GetReaderConfidenceLevel() const override
A local file representation for streams.
virtual void SetActiveSimulation(Simulation::Pointer activeSimulation)=0
void AddExtension(const std::string &extension)
void SetCategory(const std::string &category)
static mitk::CustomMimeType CreateSimulationMimeType()
ConfidenceLevel
A confidence level describing the confidence of the reader or writer in handling the given data...
virtual ConfidenceLevel GetWriterConfidenceLevel() const override
mitk::BaseProperty::Pointer GetProperty(const char *propertyKey) const
Get the property (instance of BaseProperty) with key propertyKey from the PropertyList, and set it to this, respectively;.
Abstract class for implementing a reader and writer.
virtual Simulation::Pointer GetActiveSimulation() const =0
void Write() override
Write the base data to the specified location or output stream.