| 816 | |
| 817 | #if !STEP_READER_FIXED |
| 818 | Expected<void> repairStepFile( STEPControl_Reader& reader ) |
| 819 | { |
| 820 | const auto model = reader.StepModel(); |
| 821 | const auto protocol = Handle( StepData_Protocol )::DownCast( model->Protocol() ); |
| 822 | |
| 823 | StepData_StepWriter sw( model ); |
| 824 | sw.SendModel( protocol ); |
| 825 | |
| 826 | #if STEP_READSTREAM_SUPPORTED |
| 827 | std::stringstream buffer; |
| 828 | if ( !sw.Print( buffer ) ) |
| 829 | return unexpected( "Failed to repair STEP model" ); |
| 830 | |
| 831 | buffer.seekp( 0, std::ios::beg ); |
| 832 | |
| 833 | reader = STEPControl_Reader(); |
| 834 | return readFromStream( reader, buffer ); |
| 835 | #else |
| 836 | std::unique_lock lock( cOpenCascadeTempFileMutex ); |
| 837 | |
| 838 | const auto auxFilePath = getStepTemporaryDirectory() / "auxFile.step"; |
| 839 | std::error_code ec; |
| 840 | MR_FINALLY { |
| 841 | std::filesystem::remove( auxFilePath, ec ); |
| 842 | }; |
| 843 | |
| 844 | { |
| 845 | // NOTE: opening the file in binary mode and passing to the StepData_StepWriter object lead to segfault |
| 846 | std::ofstream ofs( auxFilePath ); |
| 847 | if ( !ofs ) |
| 848 | return unexpected( std::string( "Cannot open buffer file" ) ); |
| 849 | |
| 850 | if ( !sw.Print( ofs ) ) |
| 851 | return unexpected( "Failed to repair STEP model" ); |
| 852 | } |
| 853 | |
| 854 | reader = STEPControl_Reader(); |
| 855 | return readFromFile( reader, auxFilePath ); |
| 856 | #endif |
| 857 | } |
| 858 | #endif |
| 859 | |
| 860 | std::mutex cOpenCascadeMutex = {}; |
no test coverage detected