554 |
554 |
555 fullSubfileName = subfileDirectory + "/" + Basename(parentDocumentPath) + "s" + digits + ".dat"; |
555 fullSubfileName = subfileDirectory + "/" + Basename(parentDocumentPath) + "s" + digits + ".dat"; |
556 } while (m_documents->findDocumentByName("s\\" + Basename(fullSubfileName)) != nullptr or QFile {fullSubfileName}.exists()); |
556 } while (m_documents->findDocumentByName("s\\" + Basename(fullSubfileName)) != nullptr or QFile {fullSubfileName}.exists()); |
557 } |
557 } |
558 |
558 |
559 // Determine the BFC winding type used in the main document. It will be carried over to the subfile. |
|
560 BfcStatement winding = BfcStatement::NoCertify; |
|
561 for (LDObjectIterator<LDBfc> it (currentDocument()); it.isValid(); ++it) |
|
562 { |
|
563 if (isOneOf(it->statement(), BfcStatement::CertifyCCW, BfcStatement::CertifyCW, BfcStatement::NoCertify)) |
|
564 { |
|
565 winding = it->statement(); |
|
566 break; |
|
567 } |
|
568 } |
|
569 |
|
570 // Create the new subfile document |
559 // Create the new subfile document |
571 LDDocument* subfile = m_window->newDocument(); |
560 LDDocument* subfile = m_window->newDocument(); |
572 subfile->setFullPath(fullSubfileName); |
561 subfile->setFullPath(fullSubfileName); |
573 subfile->setName(LDDocument::shortenName(fullSubfileName)); |
562 subfile->header.description = subfileTitle; |
574 |
563 subfile->header.type = LDHeader::Subpart; |
575 Model header {m_documents}; |
564 subfile->header.name = LDDocument::shortenName(fullSubfileName); |
576 header.emplace<LDComment>(subfileTitle); |
565 subfile->header.author = format("%1 [%2]", m_config->defaultName(), m_config->defaultUser()); |
577 header.emplace<LDComment>("Name: "); // This gets filled in when the subfile is saved |
566 |
578 header.emplace<LDComment>(format("Author: %1 [%2]", m_config->defaultName(), m_config->defaultUser())); |
567 if (::config->useCaLicense()) |
579 header.emplace<LDComment>("!LDRAW_ORG Unofficial_Subpart"); |
568 subfile->header.license = LDHeader::CaLicense; |
580 |
569 |
581 QString license = preferredLicenseText(); |
570 subfile->setWinding(currentDocument()->winding()); |
582 if (not license.isEmpty()) |
|
583 header.emplace<LDComment>(license); |
|
584 |
|
585 header.emplace<LDEmpty>(); |
|
586 header.emplace<LDBfc>(winding); |
|
587 header.emplace<LDEmpty>(); |
|
588 subfile->merge(header); |
|
589 |
571 |
590 // Copy the body over to the new document |
572 // Copy the body over to the new document |
591 for (LDObject* object : selectedObjects()) |
573 for (LDObject* object : selectedObjects()) |
592 Parser::parseFromString(*subfile, Parser::EndOfModel, object->asText()); |
574 Parser::parseFromString(*subfile, Parser::EndOfModel, object->asText()); |
593 |
575 |