[brlcad-commits] SF.net SVN: brlcad:[51268] brlcad/trunk/src/other/step/src/cleditor
Open Source Solid Modeling CAD
Brought to you by:
brlcad
From: <n_...@us...> - 2012-06-20 17:53:26
|
Revision: 51268 http://brlcad.svn.sourceforge.net/brlcad/?rev=51268&view=rev Author: n_reed Date: 2012-06-20 17:53:18 +0000 (Wed, 20 Jun 2012) Log Message: ----------- support for checking read/write progress; SCL git 0bea3ef Modified Paths: -------------- brlcad/trunk/src/other/step/src/cleditor/STEPfile.cc brlcad/trunk/src/other/step/src/cleditor/STEPfile.h brlcad/trunk/src/other/step/src/cleditor/STEPfile.inline.cc Modified: brlcad/trunk/src/other/step/src/cleditor/STEPfile.cc =================================================================== --- brlcad/trunk/src/other/step/src/cleditor/STEPfile.cc 2012-06-20 17:17:50 UTC (rev 51267) +++ brlcad/trunk/src/other/step/src/cleditor/STEPfile.cc 2012-06-20 17:53:18 UTC (rev 51268) @@ -56,6 +56,43 @@ return _fileName; } +/** Returns read progress,scaled 0-100. Will return a value < 0 if + * called *immediately* after read operation starts, if no file has + * been specified, or if file has been closed. If result < 50, + * ReadData1() hasn't completed yet. + * + * This function is useless unless it is called from another thread. + */ +float STEPfile::GetReadProgress() const { + if( _iFileSize < 1 ) { + return -1; + } + //the file is read once by ReadData1(), and again by ReadData2. Each gets 50%. + float percent = ( static_cast<float>( _iFileCurrentPosition ) / _iFileSize ) * 50.0; + if( _iFileStage1Done ) { + percent += 50; + } + return percent; +} + +/** Returns write progress,scaled 0-100. Will return a value < 0 if + * called *immediately* after write operation starts, if no file has + * been specified, or if file has been closed. + * \sa GetReadProgress() + * + * Caveat: Only works for files written via WriteExchangeFile() / WriteData(). + * + * This function is useless unless it is called from another thread. + */ +float STEPfile::GetWriteProgress() const { + int total = _instances.InstanceCount(); + if( total > 0 ) { + return ( static_cast<float>( _oFileInstsWritten ) / total ) * 100.0; + } else { + return -1; + } +} + /** * \param in The input stream from which the file is read. * @@ -463,6 +500,7 @@ SkipInstance( in, tmpbuf ); } else { obj = CreateInstance( in, cout ); + _iFileCurrentPosition = in.tellg(); } if( obj != ENTITY_NULL ) { @@ -511,6 +549,7 @@ _error.AppendToUserMsg( "Error in input file.\n" ); } + _iFileStage1Done = true; return instance_count; } @@ -578,6 +617,7 @@ SkipInstance( in, tmpbuf ); } else { obj = ReadInstance( in, cout, cmtStr, useTechCor ); + _iFileCurrentPosition = in.tellg(); } cmtStr.clear(); @@ -1551,12 +1591,14 @@ } void STEPfile::WriteData( ostream & out, int writeComments ) { + _oFileInstsWritten = 0; std::string currSch = schemaName(); out << "DATA;\n"; int n = instances().InstanceCount(); for( int i = 0; i < n; ++i ) { instances().GetMgrNode( i )->GetApplication_instance()->STEPwrite( out, currSch.c_str(), writeComments ); + _oFileInstsWritten++; } out << "ENDSEC;\n"; Modified: brlcad/trunk/src/other/step/src/cleditor/STEPfile.h =================================================================== --- brlcad/trunk/src/other/step/src/cleditor/STEPfile.h 2012-06-20 17:17:50 UTC (rev 51267) +++ brlcad/trunk/src/other/step/src/cleditor/STEPfile.h 2012-06-20 17:53:18 UTC (rev 51268) @@ -60,6 +60,12 @@ DirObj * _currentDir; std::string _fileName; + //the following are used to compute read/write progress + std::ifstream::pos_type _iFileSize; ///< input file size + std::ifstream::pos_type _iFileCurrentPosition; ///< input file position (from ifstream::tellg()) + bool _iFileStage1Done; ///< set immediately before ReadData1() returns + int _oFileInstsWritten; ///< number of instances that have been written + //error information ErrorDescriptor _error; @@ -110,6 +116,8 @@ } std::string SetFileName( const std::string name = "" ); std::string TruncFileName( const std::string name ) const; + float GetReadProgress() const; + float GetWriteProgress() const; //error information ErrorDescriptor & Error() { /* const */ Modified: brlcad/trunk/src/other/step/src/cleditor/STEPfile.inline.cc =================================================================== --- brlcad/trunk/src/other/step/src/cleditor/STEPfile.inline.cc 2012-06-20 17:17:50 UTC (rev 51267) +++ brlcad/trunk/src/other/step/src/cleditor/STEPfile.inline.cc 2012-06-20 17:53:18 UTC (rev 51268) @@ -1,3 +1,4 @@ + /* * NIST STEP Core Class Library * cleditor/STEPfile.inline.cc @@ -28,7 +29,9 @@ _instances( i ), _reg( r ), _fileIdIncr( 0 ), _headerId( 0 ), _entsNotCreated( 0 ), _entsInvalid( 0 ), _entsIncomplete( 0 ), _entsWarning( 0 ), _errorCount( 0 ), _warningCount( 0 ), - _maxErrorCount( 5000 ), _strict( strict ) + _maxErrorCount( 5000 ), _strict( strict ),_iFileSize( 0 ), + _iFileCurrentPosition( 0 ), _oFileInstsWritten( 0 ), + _iFileStage1Done( false ) { SetFileType( VERSION_CURRENT ); SetFileIdIncrement(); @@ -165,6 +168,8 @@ } istream * STEPfile::OpenInputFile( const std::string filename ) { + _iFileCurrentPosition = 0; + // if there's no filename to use, fail if( filename.empty() && FileName().empty() ) { _error.AppendToUserMsg( "Unable to open file for input. No current file name.\n" ); @@ -196,6 +201,10 @@ return ( 0 ); } + //check size of file + in->seekg( 0, std::ifstream::end ); + _iFileSize = in->tellg(); + in->seekg( 0, std::ifstream::beg ); return in; } @@ -203,6 +212,10 @@ if( in && *in != std::cin ) { delete in; } + + //reset file size + _iFileSize = 0; + _iFileCurrentPosition = 0; } ofstream * STEPfile::OpenOutputFile( std::string filename ) { @@ -228,10 +241,12 @@ _error.AppendToUserMsg( "unable to open file for output\n" ); _error.GreaterSeverity( SEVERITY_INPUT_ERROR ); } + _oFileInstsWritten = 0; return out; } void STEPfile::CloseOutputFile( ostream * out ) { + _oFileInstsWritten = 0; delete out; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |