/////////////////////////////////////////////////////////////////////////////// // Copyright (C) 2002-2025, Open Design Alliance (the "Alliance"). // All rights reserved. // // This software and its documentation and related materials are owned by // the Alliance. The software may only be incorporated into application // programs owned by members of the Alliance, subject to a signed // Membership Agreement and Supplemental Software License Agreement with the // Alliance. The structure and organization of this software are the valuable // trade secrets of the Alliance and its suppliers. The software is also // protected by copyright law and international treaty provisions. Application // programs incorporating this software must include the following statement // with their copyright notices: // // This application incorporates Open Design Alliance software pursuant to a license // agreement with Open Design Alliance. // Open Design Alliance Copyright (C) 2002-2025 by Open Design Alliance. // All rights reserved. // // By use of this software, its documentation or related materials, you // acknowledge and accept the above terms. /////////////////////////////////////////////////////////////////////////////// #include "OdaCommon.h" #include "OdVisualizeAssemblyCommon.h" #include "TvImport.h" #include "TvFactory.h" #include #include #include "OdPerfTimer.h" OdTvFileServices::OdTvFileServices() { #if defined(ODA_UNIXOS) m_folderDelimeter = OdChar( '/' ); #else m_folderDelimeter = OdChar( '\\' ); #endif } OdTvFileServices::~OdTvFileServices() { } OdStringArray OdTvFileServices::collectFiles( const OdString& dirPath, bool bRecursive ) { OdStringArray result; std::string stdPath( dirPath ); if( !std::filesystem::is_directory( stdPath ) ) return result; for( const auto& entry : std::filesystem::directory_iterator( stdPath ) ) { OdString path = OdString( entry.path().c_str() ); int l = path.reverseFind( m_folderDelimeter ); if( l <= 0 ) continue; OdString name = path.right( path.getLength() - l - 1 ); if( name == OD_T( "." ) || name == OD_T( ".." ) ) continue; stdPath = std::string( path ); if( std::filesystem::is_directory( stdPath ) && bRecursive ) { OdStringArray tmp = collectFiles( path, bRecursive ); for( unsigned int j = 0; j < tmp.size(); ++j ) { result.push_back( tmp[ j ] ); } } else { if( isSupportedFile( path ) ) result.push_back( path ); } } return result; } OdString OdTvFileServices::getFileExt( const OdString& fileName ) { int l = fileName.reverseFind( OdChar( '.' ) ); if( l <= 0 ) return OdString::kEmpty; OdString ext = fileName.right( fileName.getLength() - l - 1 ); ext.makeUpper(); return ext; } OdString OdTvFileServices::getFileName( const OdString& filePath ) const { int l = filePath.reverseFind( m_folderDelimeter ); if( l <= 0 ) return OdString::kEmpty; OdString name = filePath.right( filePath.getLength() - l - 1 ); return name; } bool OdTvFileServices::createDirectoryIfNotExist( const OdString& path ) { std::string stdPath( path ); if( std::filesystem::is_directory( stdPath ) ) return true; return std::filesystem::create_directory( stdPath ); } void OdTvFileServices::addSupportedExt( const OdString& ext ) { OdString val = ext; val.makeUpper(); unsigned int indx; if( m_exts.find( val, indx ) ) return; m_exts.push_back( val ); } bool OdTvFileServices::isSupportedFile( const OdString& fileName ) const { OdString ext = getFileExt( fileName ); unsigned int indx; return m_exts.find( ext, indx ); } OdTvFileConverter::OdTvFileConverter() { } OdTvFileConverter::~OdTvFileConverter() { } OdTvResult OdTvFileConverter::convertFile( const OdString& input, const OdString& output, Statistic* pStat, bool bExtPI ) { OdPerfTimerWrapper timer; if( pStat ) timer.getTimer()->start(); OdTvBaseImportParams* pPrms = getParams( input ); if( !pPrms ) return tvInvalidInput; OdTvResult tvRes = tvOk; OdTvDatabaseId dbId = odTvGetFactory().importFile( pPrms, &tvRes ); if( tvRes != tvOk ) return tvRes; dbId.openObject( OdTv::kForWrite )->addPartialViewIndexes( true, bExtPI ); OdTvVSFExportOptions opts; opts.compression = OdTvVSFExportOptions::kInt16; opts.normalsCompression = OdTvVSFExportOptions::kTwoFloats; opts.m_IgnoreFaceNormals = true; tvRes = dbId.openObject()->writeVSFX( output, &opts ); odTvGetFactory().removeDatabase( dbId ); if( pStat ) { timer.getTimer()->stop(); pStat->conversionTime = timer.getTimer()->countedMSec(); pStat->fileSize = std::filesystem::file_size( std::string( output ) ); } return tvRes; } OdTvBaseImportParams* OdTvFileConverter::getParams( const OdString& input ) { OdString ext = OdTvFileServices::getFileExt( input ); if( ext.isEmpty() ) return nullptr; OdTvBaseImportParams* pResult = nullptr; if( ext == OD_T( "DWG" ) ) { OdTvDwgImportParams* pParams = new OdTvDwgImportParams; pParams->setDCRect( OdTvDCRect( 0, 1024, 768, 0 ) ); pParams->setObjectNaming( true ); pParams->setStoreSourceObjects( true ); pParams->setClearEmptyObjects( true ); pResult = pParams; } else if( ext == OD_T( "IFC" ) ) { OdTvIfcImportParams* pParams = new OdTvIfcImportParams; pParams->setDCRect( OdTvDCRect( 0, 1024, 768, 0 ) ); pResult = pParams; } else if( ext == OD_T( "RVT" ) ) { OdTvBimImportParams* pParams = new OdTvBimImportParams; pParams->setCreate3DView( true ); pParams->setThinLines( true ); pParams->setDCRect( OdTvDCRect( 0, 1024, 768, 0 ) ); pParams->setObjectNaming( true ); pParams->setStoreSourceObjects( true ); pParams->setClearEmptyObjects( true ); pParams->setDisableFaceFillPatterns( true ); pResult = pParams; } else if( ext == OD_T( "NWD" ) ) { OdTvNwImportParams* pParams = new OdTvNwImportParams; pParams->setDCRect( OdTvDCRect( 0, 1024, 768, 0 ) ); pParams->setStoreSourceObjects( true ); pResult = pParams; } if( pResult == nullptr ) return nullptr; pResult->setFilePath( input ); return pResult; }