|
@@ -63,6 +63,11 @@ void ExportScene3MF( const char* pFile, IOSystem* pIOSystem, const aiScene* pSce
|
|
}
|
|
}
|
|
D3MF::D3MFExporter myExporter( pFile, pScene );
|
|
D3MF::D3MFExporter myExporter( pFile, pScene );
|
|
if ( myExporter.validate() ) {
|
|
if ( myExporter.validate() ) {
|
|
|
|
+ if ( pIOSystem->Exists( pFile ) ) {
|
|
|
|
+ if ( !pIOSystem->DeleteFile( pFile ) ) {
|
|
|
|
+ throw DeadlyExportError( "File exists, cannot override : " + std::string( pFile ) );
|
|
|
|
+ }
|
|
|
|
+ }
|
|
bool ok = myExporter.exportArchive(pFile);
|
|
bool ok = myExporter.exportArchive(pFile);
|
|
if ( !ok ) {
|
|
if ( !ok ) {
|
|
throw DeadlyExportError( "Could not export 3MP archive: " + std::string( pFile ) );
|
|
throw DeadlyExportError( "Could not export 3MP archive: " + std::string( pFile ) );
|
|
@@ -76,6 +81,9 @@ D3MFExporter::D3MFExporter( const char* pFile, const aiScene* pScene )
|
|
: mArchiveName( pFile )
|
|
: mArchiveName( pFile )
|
|
, m_zipArchive( nullptr )
|
|
, m_zipArchive( nullptr )
|
|
, mScene( pScene )
|
|
, mScene( pScene )
|
|
|
|
+, mModelOutput()
|
|
|
|
+, mRelOutput()
|
|
|
|
+, mContentOutput()
|
|
, mBuildItems()
|
|
, mBuildItems()
|
|
, mRelations() {
|
|
, mRelations() {
|
|
// empty
|
|
// empty
|
|
@@ -107,6 +115,7 @@ bool D3MFExporter::exportArchive( const char *file ) {
|
|
if ( nullptr == m_zipArchive ) {
|
|
if ( nullptr == m_zipArchive ) {
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
+ ok |= exportContentTypes();
|
|
ok |= export3DModel();
|
|
ok |= export3DModel();
|
|
ok |= exportRelations();
|
|
ok |= exportRelations();
|
|
|
|
|
|
@@ -116,16 +125,36 @@ bool D3MFExporter::exportArchive( const char *file ) {
|
|
return ok;
|
|
return ok;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+bool D3MFExporter::exportContentTypes() {
|
|
|
|
+ mContentOutput.clear();
|
|
|
|
+
|
|
|
|
+ mContentOutput << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
|
|
|
|
+ mContentOutput << std::endl;
|
|
|
|
+ mContentOutput << "<Types xmlns = \"http://schemas.openxmlformats.org/package/2006/content-types\">";
|
|
|
|
+ mContentOutput << std::endl;
|
|
|
|
+ mContentOutput << "<Default Extension = \"rels\" ContentType = \"application/vnd.openxmlformats-package.relationships+xml\" />";
|
|
|
|
+ mContentOutput << std::endl;
|
|
|
|
+ mContentOutput << "<Default Extension = \"model\" ContentType = \"application/vnd.ms-package.3dmanufacturing-3dmodel+xml\" />";
|
|
|
|
+ mContentOutput << std::endl;
|
|
|
|
+ mContentOutput << "</Types>";
|
|
|
|
+ mContentOutput << std::endl;
|
|
|
|
+ exportContentTyp( XmlTag::CONTENT_TYPES_ARCHIVE );
|
|
|
|
+
|
|
|
|
+ return true;
|
|
|
|
+}
|
|
|
|
+
|
|
bool D3MFExporter::exportRelations() {
|
|
bool D3MFExporter::exportRelations() {
|
|
mRelOutput.clear();
|
|
mRelOutput.clear();
|
|
|
|
|
|
- mRelOutput << "<?xml version = \"1.0\" encoding = \"UTF-8\"?>\n";
|
|
|
|
- mRelOutput << "<Relationships xmlns=\"http://schemas.openxmlformats.org/package/2006/relationships\">\n";
|
|
|
|
|
|
+ mRelOutput << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
|
|
|
|
+ mRelOutput << std::endl;
|
|
|
|
+ mRelOutput << "<Relationships xmlns=\"http://schemas.openxmlformats.org/package/2006/relationships\">";
|
|
|
|
|
|
for ( size_t i = 0; i < mRelations.size(); ++i ) {
|
|
for ( size_t i = 0; i < mRelations.size(); ++i ) {
|
|
- mRelOutput << "<Relationship Target =\"/3D/" << mRelations[ i ]->target << "\" ";
|
|
|
|
- mRelOutput << "id=\"" << mRelations[i]->id << "\" ";
|
|
|
|
- mRelOutput << "Type=\"" << mRelations[ i ]->type << "/>";
|
|
|
|
|
|
+ mRelOutput << "<Relationship Target=\"/" << mRelations[ i ]->target << "\" ";
|
|
|
|
+ mRelOutput << "Id=\"" << mRelations[i]->id << "\" ";
|
|
|
|
+ mRelOutput << "Type=\"" << mRelations[ i ]->type << "\" />";
|
|
mRelOutput << std::endl;
|
|
mRelOutput << std::endl;
|
|
}
|
|
}
|
|
mRelOutput << "</Relationships>";
|
|
mRelOutput << "</Relationships>";
|
|
@@ -157,12 +186,12 @@ bool D3MFExporter::export3DModel() {
|
|
mModelOutput << "</" << XmlTag::model << ">\n";
|
|
mModelOutput << "</" << XmlTag::model << ">\n";
|
|
|
|
|
|
OpcPackageRelationship *info = new OpcPackageRelationship;
|
|
OpcPackageRelationship *info = new OpcPackageRelationship;
|
|
- info->id = mArchiveName;
|
|
|
|
- info->target = "rel0";
|
|
|
|
- info->type = "http://schemas.microsoft.com/3dmanufacturing/2013/01/3dmodel";
|
|
|
|
|
|
+ info->id = "rel0";
|
|
|
|
+ info->target = "/3D/3DModel.model";
|
|
|
|
+ info->type = XmlTag::PACKAGE_START_PART_RELATIONSHIP_TYPE;
|
|
mRelations.push_back( info );
|
|
mRelations.push_back( info );
|
|
|
|
|
|
- writeModelToArchive( "3D", "3DModel.model" );
|
|
|
|
|
|
+ writeModelToArchive( "/3D", "3DModel.model" );
|
|
mModelOutput.flush();
|
|
mModelOutput.flush();
|
|
|
|
|
|
return true;
|
|
return true;
|
|
@@ -251,6 +280,19 @@ void D3MFExporter::writeBuild() {
|
|
mModelOutput << std::endl;
|
|
mModelOutput << std::endl;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+void D3MFExporter::exportContentTyp( const std::string &filename ) {
|
|
|
|
+ if ( nullptr == m_zipArchive ) {
|
|
|
|
+ throw DeadlyExportError( "3MF-Export: Zip archive not valid, nullptr." );
|
|
|
|
+ }
|
|
|
|
+ const std::string entry = filename;
|
|
|
|
+ zip_entry_open( m_zipArchive, entry.c_str() );
|
|
|
|
+
|
|
|
|
+ const std::string &exportTxt( mContentOutput.str() );
|
|
|
|
+ zip_entry_write( m_zipArchive, exportTxt.c_str(), exportTxt.size() );
|
|
|
|
+
|
|
|
|
+ zip_entry_close( m_zipArchive );
|
|
|
|
+}
|
|
|
|
+
|
|
void D3MFExporter::writeModelToArchive( const std::string &folder, const std::string &modelName ) {
|
|
void D3MFExporter::writeModelToArchive( const std::string &folder, const std::string &modelName ) {
|
|
if ( nullptr == m_zipArchive ) {
|
|
if ( nullptr == m_zipArchive ) {
|
|
throw DeadlyExportError( "3MF-Export: Zip archive not valid, nullptr." );
|
|
throw DeadlyExportError( "3MF-Export: Zip archive not valid, nullptr." );
|