MCPcopy Create free account
hub / github.com/MeshInspector/MeshLib / repairStepFile

Function repairStepFile

source/MRIOExtras/MRStep.cpp:818–857  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

816
817#if !STEP_READER_FIXED
818Expected<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
860std::mutex cOpenCascadeMutex = {};

Callers 2

fromStepFunction · 0.85
fromSceneStepFileFunction · 0.85

Calls 4

readFromFileFunction · 0.85
readFromStreamFunction · 0.70
unexpectedFunction · 0.50

Tested by

no test coverage detected