GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — stepcode/src/cleditor/STEPfile.inline.cc at develop · stepcode/stepcode Expand file tree/ Copy pathSTEPfile.inline.ccMore file actions 315 lines (271 loc) · 9.14 KB / Copy pathSTEPfile.inline.ccFile metadata and controls315 lines (271 loc) · 9.14 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 /* * NIST STEP Core Class Library * cleditor/STEPfile.inline.cc * April 1997 * Peter Carr * K. C. Morris * David Sauder * Development of this software was funded by the United States Government, * and is not subject to copyright. */ #include "cleditor/STEPfile.h" #include "cleditor/SdaiHeaderSchema.h" #include "clstepcore/STEPaggregate.h" #include <cmath> #include <cstring> extern void HeaderSchemaInit( Registry & reg ); //To Be inline functions //constructor & destructor STEPfile::STEPfile( Registry & r, InstMgr & i, const std::string filename, bool strict ) : _instances( i ), _reg( r ), _fileIdIncr( 0 ), _headerId( 0 ), _iFileSize( 0 ), _iFileCurrentPosition( 0 ), _iFileStage1Done( false ), _oFileInstsWritten( 0 ), _entsNotCreated( 0 ), _entsInvalid( 0 ), _entsIncomplete( 0 ), _entsWarning( 0 ), _errorCount( 0 ), _warningCount( 0 ), _maxErrorCount( 100000 ), _strict( strict ) { SetFileType( VERSION_CURRENT ); SetFileIdIncrement(); _currentDir = new DirObj( "" ); _headerRegistry = new Registry( HeaderSchemaInit ); _headerInstances = new InstMgr; if( !filename.empty() ) { ReadExchangeFile( filename ); } } STEPfile::~STEPfile() { delete _currentDir; delete _headerRegistry; _headerInstances->DeleteInstances(); delete _headerInstances; } int STEPfile::SetFileType( FileTypeCode ft ) { FileType( ft ); switch( _fileType ) { case( VERSION_OLD ): ENTITY_NAME_DELIM = '@'; FILE_DELIM = "STEP;"; END_FILE_DELIM = "ENDSTEP;"; break; case( VERSION_UNKNOWN ): case( VERSION_CURRENT ): ENTITY_NAME_DELIM = '#'; FILE_DELIM = "ISO-10303-21;"; END_FILE_DELIM = "END-ISO-10303-21;"; break; case( WORKING_SESSION ): ENTITY_NAME_DELIM = '#'; FILE_DELIM = "STEP_WORKING_SESSION;"; END_FILE_DELIM = "END-STEP_WORKING_SESSION;"; break; default: // some kind of error cerr << "Internal error: " << __FILE__ << __LINE__ << "\n" << _POC_ "\n"; return 0; } return 1; } /****************************************************** ** remove any slashes, and anything before the slash, ** from filename */ std::string STEPfile::TruncFileName( const std::string filename ) const { #if defined(_WIN32) && !defined(__mingw32__) char slash = '\\'; #else char slash = '/'; #endif size_t l = filename.find_last_of( slash ); if( l == std::string::npos ) { return filename; } else { return filename.substr( l ); } } /******************************************************/ Severity STEPfile::ReadExchangeFile( const std::string filename, bool useTechCor ) { _error.ClearErrorMsg(); _errorCount = 0; istream * in = OpenInputFile( filename ); if( _error.severity() < SEVERITY_WARNING ) { CloseInputFile( in ); return _error.severity(); } instances().ClearInstances(); if( _headerInstances ) { _headerInstances->ClearInstances(); } _headerId = 5; Severity rval = AppendFile( in, useTechCor ); CloseInputFile( in ); return rval; } Severity STEPfile::AppendExchangeFile( const std::string filename, bool useTechCor ) { _error.ClearErrorMsg(); _errorCount = 0; istream * in = OpenInputFile( filename ); if( _error.severity() < SEVERITY_WARNING ) { CloseInputFile( in ); return _error.severity(); } Severity rval = AppendFile( in, useTechCor ); CloseInputFile( in ); return rval; } /******************************************************/ Severity STEPfile::ReadWorkingFile( const std::string filename, bool useTechCor ) { _error.ClearErrorMsg(); _errorCount = 0; istream * in = OpenInputFile( filename ); if( _error.severity() < SEVERITY_WARNING ) { CloseInputFile( in ); return _error.severity(); } instances().ClearInstances(); _headerInstances->ClearInstances(); SetFileType( WORKING_SESSION ); Severity rval = AppendFile( in, useTechCor ); SetFileType(); CloseInputFile( in ); return rval; } Severity STEPfile::AppendWorkingFile( const std::string filename, bool useTechCor ) { _error.ClearErrorMsg(); _errorCount = 0; istream * in = OpenInputFile( filename ); if( _error.severity() < SEVERITY_WARNING ) { CloseInputFile( in ); return _error.severity(); } SetFileType( WORKING_SESSION ); Severity rval = AppendFile( in, useTechCor ); SetFileType(); CloseInputFile( in ); return rval; } /******************************************************/ 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" ); _error.GreaterSeverity( SEVERITY_INPUT_ERROR ); return( 0 ); } else { if( SetFileName( filename ).empty() && ( filename.compare( "-" ) != 0 ) ) { char msg[BUFSIZ+1]; snprintf( msg, sizeof(msg), "Unable to find file for input: \'%s\'. File not read.\n", filename.c_str() ); _error.AppendToUserMsg( msg ); _error.GreaterSeverity( SEVERITY_INPUT_ERROR ); return( 0 ); } } std::istream * in; if( filename.compare( "-" ) == 0 ) { in = &std::cin; } else { in = new ifstream( FileName().c_str() ); } if( !in || !( in -> good() ) ) { char msg[BUFSIZ+1]; snprintf( msg, sizeof(msg), "Unable to open file for input: \'%s\'. File not read.\n", filename.c_str() ); _error.AppendToUserMsg( msg ); _error.GreaterSeverity( SEVERITY_INPUT_ERROR ); return ( 0 ); } //check size of file in->seekg( 0, std::ifstream::end ); _iFileSize = in->tellg(); in->seekg( 0, std::ifstream::beg ); return in; } /******************************************************/ void STEPfile::CloseInputFile( istream * in ) { if (in != &std::cin) { delete in; } //reset file size _iFileSize = 0; _iFileCurrentPosition = 0; } /******************************************************/ ofstream * STEPfile::OpenOutputFile( std::string filename ) { if( filename.empty() ) { if( FileName().empty() ) { _error.AppendToUserMsg( "No current file name.\n" ); _error.GreaterSeverity( SEVERITY_INPUT_ERROR ); } } else { if( SetFileName( filename ).empty() ) { char msg[BUFSIZ+1]; snprintf( msg, sizeof(msg), "can't find file: %s\nFile not written.\n", filename.c_str() ); _error.AppendToUserMsg( msg ); _error.GreaterSeverity( SEVERITY_INPUT_ERROR ); } } if( _currentDir->FileExists( TruncFileName( filename ) ) ) { MakeBackupFile(); } ofstream * out = new ofstream( filename.c_str() ); if( !out ) { _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; } /******************************************************/ int STEPfile::IncrementFileId( int fileid ) { return ( fileid + FileIdIncr() ); } void STEPfile::SetFileIdIncrement() { if( instances().MaxFileId() < 0 ) { _fileIdIncr = 0; } else { _fileIdIncr = ( int )( ( ceil( ( instances().MaxFileId() + 99.0 ) / 1000.0 ) + 1.0 ) * 1000.0 ); } } /** * Returns the schema name from the file schema header section (or the 1st * one if more than one exists). Copies this value into schName. If there * is no header section or no value for file schema, NULL is returned and * schName is unset. */ std::string STEPfile::schemaName() { SdaiFile_schema * fs; std::string schName; STEPnode * n; if( _headerInstances == NULL ) { return schName; } fs = ( SdaiFile_schema * )_headerInstances->GetApplication_instance( "File_Schema" ); if( fs == ENTITY_NULL ) { return schName; } n = ( STEPnode * )fs->schema_identifiers_()->GetHead(); // (take the first one) if( n == NULL ) { return schName; } n->STEPwrite( schName ); if( schName.empty() || schName[0] == '$' ) { schName.clear(); return schName; } else if( schName[0] == '\0' ) { //probably never - it seems that putting null in std::string takes effort _error.AppendToUserMsg( "In STEPfile::schemaName: schName contains \\0 - it should be empty." ); _error.GreaterSeverity( SEVERITY_WARNING ); schName.clear(); return schName; } if( schName[ schName.length() - 1 ] == '\'' ) { schName = schName.substr( 1, schName.length() - 2 ); } else { _error.AppendToUserMsg( "In STEPfile::schemaName: schName was truncated." ); _error.GreaterSeverity( SEVERITY_WARNING ); schName = schName.substr( 1, schName.length() - 1 ); } return schName; } |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |