| 400 | } |
| 401 | |
| 402 | App::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 | |
| 459 | bool ImportOCAF2::createGroup( |