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

Method getDocument

src/Mod/Import/App/ImportOCAF2.cpp:402–457  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

400}
401
402App::Document* ImportOCAF2::getDocument(App::Document* doc, TDF_Label label)
403{
404 if (filePath.empty() || options.mode == SingleDoc || options.merge) {
405 return doc;
406 }
407
408 auto name = getLabelName(label);
409 if (name.empty()) {
410 return doc;
411 }
412
413 App::DocumentInitFlags initFlags {.createView = false};
414 auto newDoc = App::GetApplication().newDocument(name.c_str(), name.c_str(), initFlags);
415
416 std::ostringstream ss;
417 Base::FileInfo fi(doc->FileName.getValue());
418 std::string path = fi.dirPath();
419 if (options.mode == GroupPerDir || options.mode == ObjectPerDir) {
420 for (int i = 0; i < 1000; ++i) {
421 ss.str("");
422 ss << path << '/' << fi.fileNamePure() << "_parts";
423 if (i > 0) {
424 ss << '_' << std::setfill('0') << std::setw(3) << i;
425 }
426 Base::FileInfo fi2(ss.str());
427 if (fi2.exists()) {
428 if (!fi2.isDir()) {
429 continue;
430 }
431 }
432 else if (!fi2.createDirectory()) {
433 FC_WARN("Failed to create directory " << fi2.filePath());
434 break;
435 }
436 path = fi2.filePath();
437 break;
438 }
439 }
440 for (int i = 0; i < 1000; ++i) {
441 ss.str("");
442 ss << path << '/' << newDoc->getName() << ".fcstd";
443 if (i > 0) {
444 ss << '_' << std::setfill('0') << std::setw(3) << i;
445 }
446 Base::FileInfo fi(ss.str());
447 if (!fi.exists()) {
448 if (!newDoc->saveAs(fi.filePath().c_str())) {
449 break;
450 }
451 return newDoc;
452 }
453 }
454
455 FC_WARN("Cannot save document for part '" << name << "'");
456 return doc;
457}
458
459bool ImportOCAF2::createGroup(

Callers 13

getIconMethod · 0.45
VisualInspectionMethod · 0.45
acceptMethod · 0.45
insertFunction · 0.45
importerMethod · 0.45
readDXFMethod · 0.45
createGroupMethod · 0.45
loadShapesMethod · 0.45
loadShapeMethod · 0.45
exportObjectsMethod · 0.45
insertMethod · 0.45
readDXFMethod · 0.45

Calls 13

dirPathMethod · 0.80
fileNamePureMethod · 0.80
isDirMethod · 0.80
createDirectoryMethod · 0.80
emptyMethod · 0.45
newDocumentMethod · 0.45
c_strMethod · 0.45
getValueMethod · 0.45
strMethod · 0.45
existsMethod · 0.45
filePathMethod · 0.45
getNameMethod · 0.45

Tested by 3

getIconMethod · 0.36
VisualInspectionMethod · 0.36
acceptMethod · 0.36