MCPcopy Create free account
hub / github.com/MITK/MITK / Save

Method Save

Modules/Persistence/src/mitkPersistenceService.cpp:104–188  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

102}
103
104bool mitk::PersistenceService::Save(const std::string &fileName, bool appendChanges)
105{
106 this->Initialize();
107 bool save = false;
108 std::string theFile = fileName;
109 if (theFile.empty())
110 theFile = PersistenceService::GetDefaultPersistenceFile();
111
112 std::string thePath = itksys::SystemTools::GetFilenamePath(theFile.c_str());
113 if (!thePath.empty() && !itksys::SystemTools::FileExists(thePath.c_str()))
114 {
115 if (!itksys::SystemTools::MakeDirectory(thePath.c_str()))
116 {
117 MITK_ERROR("PersistenceService") << "Could not create " << thePath;
118 return false;
119 }
120 }
121
122 bool createFile = !itksys::SystemTools::FileExists(theFile.c_str());
123 if (!itksys::SystemTools::Touch(theFile.c_str(), createFile))
124 {
125 MITK_ERROR("PersistenceService") << "Could not create or write to " << theFile;
126 return false;
127 }
128
129 bool xmlFile = false;
130 if (itksys::SystemTools::GetFilenameLastExtension(theFile.c_str()) == ".xml")
131 xmlFile = true;
132
133 mitk::DataStorage::Pointer tempDs;
134 if (appendChanges)
135 {
136 if (xmlFile == false)
137 {
138 if (itksys::SystemTools::FileExists(theFile.c_str()))
139 {
140 bool load = false;
141 DataStorage::Pointer ds = m_SceneIO->LoadScene(theFile);
142 load = (m_SceneIO->GetFailedNodes() == nullptr || m_SceneIO->GetFailedNodes()->size() == 0) &&
143 (m_SceneIO->GetFailedNodes() == nullptr || m_SceneIO->GetFailedProperties()->IsEmpty());
144 if (!load)
145 return false;
146
147 tempDs = ds;
148 }
149 }
150 else
151 {
152 tempDs = mitk::StandaloneDataStorage::New();
153 if (xmlFile && appendChanges && itksys::SystemTools::FileExists(theFile.c_str()))
154 {
155 if (!m_PropertyListsXmlFileReaderAndWriter->ReadLists(theFile, m_PropertyLists))
156 return false;
157 }
158 }
159
160 this->RestorePropertyListsFromPersistentDataNodes(tempDs);
161 }

Callers 3

SetAutoLoadAndSaveMethod · 0.95
UnitializeMethod · 0.95
PersistenceTestMethod · 0.45

Calls 15

InitializeMethod · 0.95
GetDataNodesMethod · 0.95
GetFailedNodesMethod · 0.80
ReadListsMethod · 0.80
WriteListsMethod · 0.80
SaveSceneMethod · 0.80
GetPointerMethod · 0.80
NewFunction · 0.50
emptyMethod · 0.45
LoadSceneMethod · 0.45
sizeMethod · 0.45

Tested by 1

PersistenceTestMethod · 0.36