MCPcopy Create free account
hub / github.com/FreeCAD/FreeCAD / openDocumentPrivate

Method openDocumentPrivate

src/App/Application.cpp:1181–1284  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1179}
1180
1181Document* 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 }

Callers

nothing calls this directly

Calls 15

FileSystemErrorFunction · 0.85
fileNamePureMethod · 0.80
FileInfoClass · 0.50
existsMethod · 0.45
strMethod · 0.45
c_strMethod · 0.45
filePathMethod · 0.45
testStatusMethod · 0.45
getNameMethod · 0.45
getObjectMethod · 0.45
getObjectsMethod · 0.45
getNameInDocumentMethod · 0.45

Tested by

no test coverage detected