| 1179 | } |
| 1180 | |
| 1181 | Document* Application::openDocumentPrivate(const char * FileName, |
| 1182 | const char *propFileName, const char *label, |
| 1183 | bool isMainDoc, DocumentInitFlags initFlags, |
| 1184 | std::vector<std::string> &&objNames) |
| 1185 | { |
| 1186 | Base::FileInfo File(FileName); |
| 1187 | |
| 1188 | if (!File.exists()) { |
| 1189 | std::stringstream str; |
| 1190 | str << "File '" << FileName << "' does not exist!"; |
| 1191 | throw Base::FileSystemError(str.str()); |
| 1192 | } |
| 1193 | |
| 1194 | // Before creating a new document we check whether the document is already open |
| 1195 | auto doc = getDocumentByPath(File.filePath().c_str(), PathMatchMode::MatchCanonicalWarning); |
| 1196 | if(doc) { |
| 1197 | if(doc->testStatus(Document::PartialDoc) |
| 1198 | || doc->testStatus(Document::PartialRestore)) { |
| 1199 | // Here means a document is already partially loaded, but the document |
| 1200 | // is requested again, either partial or not. We must check if the |
| 1201 | // document contains the required object |
| 1202 | |
| 1203 | if(isMainDoc) { |
| 1204 | // Main document must be open fully, so close and reopen |
| 1205 | closeDocument(doc->getName()); |
| 1206 | doc = nullptr; |
| 1207 | } else if(_allowPartial) { |
| 1208 | bool reopen = false; |
| 1209 | for(const auto &name : objNames) { |
| 1210 | auto obj = doc->getObject(name.c_str()); |
| 1211 | if(!obj || obj->testStatus(PartialObject)) { |
| 1212 | reopen = true; |
| 1213 | // NOTE: We are about to reload this document with |
| 1214 | // extra objects. However, it is possible to repeat |
| 1215 | // this process several times, if it is linked by |
| 1216 | // multiple documents and each with a different set of |
| 1217 | // objects. To partially solve this problem, we do not |
| 1218 | // close and reopen the document immediately here, but |
| 1219 | // add it to _pendingDocsReopen to delay reloading. |
| 1220 | for(auto obj2 : doc->getObjects()) |
| 1221 | objNames.emplace_back(obj2->getNameInDocument()); |
| 1222 | _pendingDocMap[doc->FileName.getValue()] = objNames; |
| 1223 | break; |
| 1224 | } |
| 1225 | } |
| 1226 | if(!reopen) |
| 1227 | return nullptr; |
| 1228 | } |
| 1229 | |
| 1230 | if(doc) { |
| 1231 | _pendingDocsReopen.emplace_back(FileName); |
| 1232 | return nullptr; |
| 1233 | } |
| 1234 | } |
| 1235 | |
| 1236 | if (!isMainDoc) { |
| 1237 | return nullptr; |
| 1238 | } |
nothing calls this directly
no test coverage detected