Branch data Line data Source code
1 : : /*******************************************************************************
2 : : COPYRIGHT 2002 CATERPILLAR INC. ALL RIGHTS RESERVED
3 : :
4 : : This program is the property of Caterpillar Inc., includes Caterpillar's
5 : : confidential and trade secret information, and is maintained as an
6 : : unpublished copyrighted work. It is not to be copied or used by others
7 : : except under license from Caterpillar. This program is also protected as an
8 : : unpublished work in accordance with the copyright act of 1976. In the event
9 : : of either inadvertent or deliberate publication, Caterpillar Inc. intends to
10 : : maintain copyright protection for this work under the relevant copyright
11 : : laws pertaining to published works. The inclusion of a copyright notice
12 : : hereon is precautionary only, and does not imply publication or disclosure.
13 : :
14 : :
15 : : Filename : CCubitFile.cpp
16 : :
17 : : Purpose : Implements reading and writing data in the Cubit file format.
18 : :
19 : : Special Notes :
20 : :
21 : : Creator : Will A. Helden
22 : :
23 : : Creation Date : 02/15/02
24 : :
25 : : Owner : Will A. Helden
26 : :
27 : : *******************************************************************************/
28 : :
29 : : #include "CCubitFile.hpp"
30 : : #include "CubitDefines.h"
31 : : #include "CubitFileIOWrapper.hpp"
32 : : #include "CubitFileMetaData.hpp"
33 : : #include "CubitFileFEModel.hpp"
34 : : #include "CubitFileSimModel.hpp"
35 : : #include <cstring>
36 : : #include "CubitFileUtil.hpp"
37 : :
38 : : using namespace NCubitFile;
39 : :
40 : : ///////////////////////////////////////////////////////////////////////////////
41 : : // Construction/Destruction
42 : : ///////////////////////////////////////////////////////////////////////////////
43 : :
44 : : /* Note: some platforms define both BIG_ENDIAN and LITTLE_ENDIAN
45 : : so don't do if defined(LITTLE_ENDIAN) here. Compare to BYTE_ORDER instead. */
46 : : #if defined(_WIN32) || defined(__LITTLE_ENDIAN__) || defined(CUBIT_LINUX) || (defined(LITTLE_ENDIAN) && (BYTE_ORDER==LITTLE_ENDIAN)) /* should be little endian platforms */
47 : : const UnsignedInt32 CCubitFile::mintNativeEndian = 0;
48 : : #else // big endian platforms
49 : : const UnsignedInt32 CCubitFile::mintNativeEndian = 0xFFFFFFFF;
50 : : #endif
51 : : const UnsignedInt32 CCubitFile::mintSizeOfContents =
52 : : sizeof(SCubitFileContentsHeader) / sizeof(UnsignedInt32);
53 : : const UnsignedInt32 CCubitFile::mintSizeOfModel =
54 : : sizeof(SCubitFileModelEntry) / sizeof(UnsignedInt32);
55 : :
56 [ # # ]: 0 : CCubitFile::CCubitFile()
57 : : {
58 : 0 : meErrorState = eSuccess;
59 : 0 : mintNextModelID = 1;
60 : :
61 : 0 : mpaReadModels = mpaWriteModels = NULL;
62 : 0 : mpaReadModelStat = NULL;
63 : 0 : mpMetaData = NULL;
64 : 0 : mstrReadFileName = mstrWriteFileName = mstrBackupFileName = NULL;
65 : 0 : mpReadFEModel = mpWriteFEModel = NULL;
66 : 0 : mpReadSimModel = mpWriteSimModel = NULL;
67 : :
68 : 0 : mModelBuff.mintNumModels = 0;
69 : 0 : mModelBuff.mpaModelData = NULL;
70 : 0 : }
71 : :
72 [ # # ]: 0 : CCubitFile::~CCubitFile()
73 : : {
74 : : // auto-save?
75 : : // delete incomplete temp files
76 [ # # ]: 0 : FreeAll();
77 : :
78 : : // Assume if any FE models are still around now (i.e. EndRead/Write hasn't
79 : : // been called) there was an error, so free their memory.
80 [ # # ]: 0 : if(mpReadFEModel)
81 [ # # ][ # # ]: 0 : delete mpReadFEModel;
82 [ # # ]: 0 : if(mpWriteFEModel)
83 [ # # ][ # # ]: 0 : delete mpWriteFEModel;
84 [ # # ]: 0 : if(mpReadSimModel)
85 [ # # ][ # # ]: 0 : delete mpReadSimModel;
86 [ # # ]: 0 : if(mpWriteSimModel)
87 [ # # ][ # # ]: 0 : delete mpWriteSimModel;
88 : :
89 [ # # ]: 0 : if(mModelBuff.mpaModelData)
90 [ # # ]: 0 : delete [] mModelBuff.mpaModelData;
91 [ # # ]: 0 : }
92 : :
93 : 0 : void CCubitFile::FreeAll()
94 : : // Frees all allocated memory, closes open files, and resets class members to
95 : : // their constructed state.
96 : : {
97 : : // Free all allocated memory.
98 [ # # ]: 0 : if(mstrReadFileName)
99 [ # # ]: 0 : delete [] mstrReadFileName;
100 [ # # ]: 0 : if(mstrWriteFileName)
101 [ # # ]: 0 : delete [] mstrWriteFileName;
102 [ # # ]: 0 : if(mstrBackupFileName)
103 [ # # ]: 0 : delete [] mstrBackupFileName;
104 : 0 : mstrReadFileName = mstrWriteFileName = mstrBackupFileName = NULL;
105 [ # # ]: 0 : if(mpaReadModels)
106 [ # # ]: 0 : delete [] mpaReadModels;
107 [ # # ]: 0 : if(mpaWriteModels)
108 [ # # ]: 0 : delete [] mpaWriteModels;
109 : 0 : mpaReadModels = mpaWriteModels = NULL;
110 [ # # ]: 0 : if(mpaReadModelStat)
111 [ # # ]: 0 : delete [] mpaReadModelStat;
112 : 0 : mpaReadModelStat = NULL;
113 [ # # ]: 0 : if(mpMetaData)
114 [ # # ]: 0 : delete mpMetaData;
115 : 0 : mpMetaData = NULL;
116 : :
117 : : // Close any open files.
118 : : try {
119 [ # # ][ # # ]: 0 : if(mpReadFile)
120 [ # # ]: 0 : mpReadFile.close();
121 [ # # ][ # # ]: 0 : if(mpWriteFile)
122 [ # # ]: 0 : mpWriteFile.close();
123 : : }
124 : 0 : catch(...) { }
125 : 0 : }
126 : :
127 : 0 : CCubitFile::EErrorCode CCubitFile::Open(const char* xstrReadFileName,
128 : : const char* xstrWriteFileName,
129 : : const char* xstrBackupFileName)
130 : : // Open a file for reading or writing.
131 : : // === NOTES ===
132 : : // * The read file is a file to be read only. The file must exist and be
133 : : // accessable or this function will fail.
134 : : // * The write file is an output file. The file must be creatable or this
135 : : // function will fail. If the file already exists, it will be overwritten.
136 : : // If the write file name is the same as the read file name, a temporary
137 : : // write file name will be generated to be written to until the completion
138 : : // of the write operation at which time the read file will be deleted and
139 : : // the write file renamed to take its place.
140 : : // * The backup file name is used for preventing the loss of old read files.
141 : : // If the read file was to be deleted automatically by a write operation,
142 : : // specification of a backup name, will cause the read file to be renamed
143 : : // instead.
144 : : // * Any of these three filenames may be NULL, but at least one name, read or
145 : : // write, must be specified.
146 : : {
147 : : try {
148 [ # # ][ # # ]: 0 : if(!xstrReadFileName && !xstrWriteFileName)
149 : 0 : throw ePassedNullPointer;
150 : :
151 [ # # ][ # # ]: 0 : mpMetaData = new CMetaData;
152 : :
153 : : // If a file has been designated for reading, copy its name and try to
154 : : // open it.
155 [ # # ]: 0 : if(xstrReadFileName ) {
156 : 0 : UnsignedInt32 lintFileName = std::strlen(xstrReadFileName);
157 [ # # ]: 0 : mstrReadFileName = new char[lintFileName + 1];
158 : 0 : std::strcpy(mstrReadFileName, xstrReadFileName);
159 : :
160 [ # # ]: 0 : if( !xstrWriteFileName )
161 : : {
162 [ # # ][ # # ]: 0 : mpReadFile.open(mstrReadFileName, "rb");
[ # # ]
163 [ # # ][ # # ]: 0 : if(!mpReadFile)
164 : 0 : throw eFileReadError;
165 : :
166 : : // Test to see if the file is a cubit file... it should begin with
167 : : // the string 'CUBE'.
168 : : unsigned char lachrMagic[4];
169 [ # # ][ # # ]: 0 : if(fread(lachrMagic, 1, 4, mpReadFile.file()) != 4)
[ # # ]
170 : 0 : throw eFileUnrecognizedFormat;
171 [ # # ][ # # ]: 0 : if((lachrMagic[0] != 'C') || (lachrMagic[1] != 'U') ||
[ # # ]
172 [ # # ]: 0 : (lachrMagic[2] != 'B') || (lachrMagic[3] != 'E'))
173 : 0 : throw eFileUnrecognizedFormat;
174 : :
175 : : // Load the file's "table of contents".
176 [ # # ][ # # ]: 0 : CIOWrapper lIO(mpReadFile.file(), 4, 0);
177 [ # # ]: 0 : lIO.BeginReadBlock(4);
178 [ # # ]: 0 : lIO.Read((UnsignedInt32*)&mReadContents, mintSizeOfContents);
179 [ # # ]: 0 : lIO.EndReadBlock();
180 : :
181 [ # # ]: 0 : if(mReadContents.mintHeaderSchema > 0)
182 : 0 : throw eFileUnrecognizedFormat;
183 : :
184 [ # # ]: 0 : if(mReadContents.mintNumModels) {
185 : : mpaReadModels =
186 [ # # ][ # # ]: 0 : new SCubitFileModelEntry[mReadContents.mintNumModels];
187 [ # # ][ # # ]: 0 : mpaReadModelStat = new EModelStat[mReadContents.mintNumModels];
188 [ # # ][ # # ]: 0 : if(!mpaReadModels || !mpaReadModelStat) throw eMemoryError;
189 : :
190 [ # # ]: 0 : lIO.BeginReadBlock(mReadContents.mintModelTableOffset);
191 : : lIO.Read((UnsignedInt32*)mpaReadModels,
192 [ # # ]: 0 : mReadContents.mintNumModels * mintSizeOfModel);
193 [ # # ]: 0 : lIO.EndReadBlock();
194 : :
195 : : UnsignedInt32 lintMod;
196 [ # # ]: 0 : for(lintMod = 0; lintMod < mReadContents.mintNumModels; lintMod++) {
197 : 0 : mpaReadModelStat[lintMod] = eStatNotWritten;
198 [ # # ]: 0 : if(mpaReadModels[lintMod].mintModelHandle >= mintNextModelID)
199 : 0 : mintNextModelID = mpaReadModels[lintMod].mintModelHandle + 1;
200 : : }
201 : : }
202 : :
203 : : // Read the file-scoped (model) meta-data.
204 : : mpMetaData->ReadMetaData(mpReadFile.file(),
205 : : mReadContents.mintModelMetaDataOffset, 0,
206 [ # # ][ # # ]: 0 : mReadContents.mintHeaderSourceEndian);
[ # # ]
207 : : }
208 : : else
209 : : {
210 : 0 : mReadContents.mintHeaderSourceEndian = mintNativeEndian;
211 : 0 : mReadContents.mintHeaderSchema = 0;
212 : 0 : mReadContents.mintNumModels = 0;
213 : 0 : mReadContents.mintModelTableOffset = 0;
214 : 0 : mReadContents.mintModelMetaDataOffset = 0;
215 : 0 : mReadContents.mintActiveFEModel = 0;
216 : :
217 : : // Copy the backup file name, if specified.
218 [ # # ]: 0 : if(xstrBackupFileName) {
219 : 0 : UnsignedInt32 lintFileName = std::strlen(xstrBackupFileName);
220 [ # # ]: 0 : mstrBackupFileName = new char[lintFileName + 1];
221 : 0 : std::strcpy(mstrBackupFileName, xstrBackupFileName);
222 : : }
223 : : }
224 : : }
225 : : else {
226 : : // If there wasn't a file to read, initialize the read contents to
227 : : // nothing.
228 : 0 : mReadContents.mintHeaderSourceEndian = mintNativeEndian;
229 : 0 : mReadContents.mintHeaderSchema = 0;
230 : 0 : mReadContents.mintNumModels = 0;
231 : 0 : mReadContents.mintModelTableOffset = 0;
232 : 0 : mReadContents.mintModelMetaDataOffset = 0;
233 : 0 : mReadContents.mintActiveFEModel = 0;
234 : : }
235 : :
236 : : // If a file has been designated for writing
237 [ # # ]: 0 : if(xstrWriteFileName) {
238 : 0 : UnsignedInt32 lintFileName = std::strlen(xstrWriteFileName);
239 [ # # ]: 0 : mstrWriteFileName = new char[lintFileName + 10];
240 : :
241 : : // If the read and write file names don't match, then the write
242 : : // file can be opened by name.
243 [ # # ][ # # ]: 0 : if(!mstrReadFileName || std::strcmp(mstrReadFileName, xstrWriteFileName)) {
244 : 0 : mintWriteTempFile = 0;
245 : 0 : std::strcpy(mstrWriteFileName, xstrWriteFileName);
246 [ # # ][ # # ]: 0 : mpWriteFile.open(mstrWriteFileName, "wb");
[ # # ]
247 : : }
248 : : // Otherwise, generate a temporary file name to write to so that
249 : : // the read file's contents will not be destroyed until it is
250 : : // verifiable that any new writes are successful.
251 : : else {
252 : 0 : mintWriteTempFile = 1;
253 : 0 : UnsignedInt32 lintTempFile = 0;
254 [ # # ][ # # ]: 0 : while(!mpWriteFile && (lintTempFile < 0xFF)) {
[ # # ][ # # ]
255 : : sprintf(mstrWriteFileName, "%s~%.2x.tmp",
256 : 0 : mstrReadFileName, lintTempFile);
257 [ # # ][ # # ]: 0 : mpWriteFile.open(mstrWriteFileName, "wb");
[ # # ]
258 : 0 : lintTempFile++;
259 : : }
260 : : }
261 [ # # ][ # # ]: 0 : if(!mpWriteFile)
262 : 0 : throw eFileWriteError;
263 : :
264 : : // Initialize the write file contents - copy the model inventory
265 : : // (but not actual contents yet) from the read file.
266 : 0 : mWriteContents.mintHeaderSourceEndian = mintNativeEndian;
267 : 0 : mWriteContents.mintHeaderSchema = 0;
268 : 0 : mWriteContents.mintNumModels = mReadContents.mintNumModels;
269 : 0 : mWriteContents.mintModelTableOffset = 0;
270 : 0 : mWriteContents.mintModelMetaDataOffset = 0;
271 : 0 : mWriteContents.mintActiveFEModel = mReadContents.mintActiveFEModel;
272 : 0 : mintWriteBuffNumModels = 0;
273 : :
274 [ # # ]: 0 : if(mWriteContents.mintNumModels) {
275 : : mpaWriteModels =
276 [ # # ][ # # ]: 0 : new SCubitFileModelEntry[mWriteContents.mintNumModels];
277 [ # # ]: 0 : if(!mpaWriteModels) throw eMemoryError;
278 : :
279 : : UnsignedInt32 lintMod;
280 [ # # ]: 0 : for(lintMod = 0; lintMod < mWriteContents.mintNumModels; lintMod++) {
281 : 0 : mpaWriteModels[lintMod].mintModelHandle =
282 : 0 : mpaReadModels[lintMod].mintModelHandle;
283 : 0 : mpaWriteModels[lintMod].mintModelOffset = 0;
284 : 0 : mpaWriteModels[lintMod].mintModelLength = 0;
285 : 0 : mpaWriteModels[lintMod].mintModelType =
286 : 0 : mpaReadModels[lintMod].mintModelType;
287 : 0 : mpaWriteModels[lintMod].mintModelOwner =
288 : 0 : mpaReadModels[lintMod].mintModelOwner;
289 : : }
290 : : }
291 : :
292 : : // Initialize the write file by writing its identity and an initial
293 : : // table of contents.
294 [ # # ][ # # ]: 0 : CIOWrapper lIO(mpWriteFile.file());
295 [ # # ]: 0 : lIO.BeginWriteBlock(0);
296 [ # # ]: 0 : lIO.Write("CUBE", 4);
297 [ # # ]: 0 : lIO.Write((UnsignedInt32*)&mWriteContents, mintSizeOfContents);
298 [ # # ]: 0 : lIO.EndWriteBlock();
299 : :
300 [ # # ][ # # ]: 0 : WriteModelTable();
301 : : }
302 : : else {
303 : : // If there wasn't a file to written, initialize the write contents
304 : : // to nothing.
305 : 0 : mWriteContents.mintHeaderSourceEndian = mintNativeEndian;
306 : 0 : mWriteContents.mintHeaderSchema = 0;
307 : 0 : mWriteContents.mintNumModels = 0;
308 : 0 : mWriteContents.mintModelTableOffset = 0;
309 : 0 : mWriteContents.mintModelMetaDataOffset = 0;
310 : 0 : mWriteContents.mintActiveFEModel = 0;
311 : : }
312 : :
313 : 0 : return eSuccess;
314 : : }
315 : :
316 : : // Handle all open errors by reseting the file object.
317 : 0 : catch(EErrorCode xeErrorCode) {
318 [ # # ]: 0 : FreeAll();
319 : 0 : return xeErrorCode;
320 : : }
321 [ # # ]: 0 : catch(...) {
322 [ # # ]: 0 : FreeAll();
323 : 0 : return eUnknownError;
324 : : }
325 : : }
326 : :
327 : 0 : CCubitFile::EErrorCode CCubitFile::Close()
328 : : // Close any open files, completing any pending write operations, and free any
329 : : // allocated resources. See Open() comments for more info.
330 : : {
331 : : try {
332 : :
333 [ # # ][ # # ]: 0 : if(mpWriteFile) {
334 : : // Write file scoped (model) metadata and update the file's table
335 : : // of contents one last time.
336 : : UnsignedInt32 lintMetaDataLength;
337 : : mpMetaData->WriteMetaData(mpWriteFile.file(),
338 [ # # ][ # # ]: 0 : mWriteContents.mintModelMetaDataOffset, lintMetaDataLength);
339 [ # # ]: 0 : WriteModelTable();
340 : :
341 : : // throw away erroneously written files?!?
342 : :
343 : : // If the written file was a temporary file, delete the original
344 : : // file and replace it with the temporary file.
345 [ # # ]: 0 : if(mintWriteTempFile) {
346 : : // Close any open files.
347 [ # # ]: 0 : mpReadFile.close();
348 [ # # ]: 0 : mpWriteFile.close();
349 : :
350 : : // If there was a backup name specified for the old read file
351 : : // rename it instead of deleting it.
352 [ # # ]: 0 : if(mstrBackupFileName)
353 [ # # ][ # # ]: 0 : CubitFileUtil::rename_file(mstrReadFileName, mstrBackupFileName);
[ # # ][ # # ]
[ # # ]
354 : : else
355 [ # # ][ # # ]: 0 : CubitFileUtil::remove_file(mstrReadFileName);
[ # # ]
356 [ # # ][ # # ]: 0 : if(CUBIT_SUCCESS != CubitFileUtil::rename_file(mstrWriteFileName, mstrReadFileName))
[ # # ][ # # ]
[ # # ][ # # ]
357 : 0 : throw eUnknownError;
358 : : }
359 : : }
360 : :
361 : : // Close any open files and clean up allocated memory.
362 [ # # ]: 0 : FreeAll();
363 : 0 : return eSuccess;
364 : : }
365 : 0 : catch(EErrorCode xeErrorCode) {
366 [ # # ]: 0 : FreeAll();
367 : 0 : return xeErrorCode;
368 : : }
369 [ # # ]: 0 : catch(...) {
370 [ # # ]: 0 : FreeAll();
371 : 0 : return eUnknownError;
372 : : }
373 : : }
374 : :
375 : : /*UnsignedInt32 CCubitFile::GetModelList(UnsignedInt32& xintNumModels,
376 : : const SModelData*& xpaModels)
377 : : // Returns a list of all models contained in the file.
378 : : {
379 : : SCubitFileModelEntry* lpaModels = NULL;
380 : : if(mpaWriteModels) {
381 : : lpaModels = mpaWriteModels;
382 : : xintNumModels = mWriteContents.mintNumModels;
383 : : }
384 : : else if(mpaReadModels) {
385 : : lpaModels = mpaReadModels;
386 : : xintNumModels = mReadContents.mintNumModels;
387 : : }
388 : :
389 : : if(!lpaModels || !xintNumModels) {
390 : : xpaModels = NULL;
391 : : return eNotFound;
392 : : }
393 : :
394 : : if(mModelBuff.mintNumModels < xintNumModels) {
395 : : mModelBuff.mintNumModels = xintNumModels;
396 : : if(mModelBuff.mpaModelData)
397 : : delete [] mModelBuff.mpaModelData;
398 : : mModelBuff.mpaModelData = new SModelData[xintNumModels];
399 : : }
400 : : xpaModels = mModelBuff.mpaModelData;
401 : :
402 : : for(UnsignedInt32 lintModel = 0; lintModel < xintNumModels; lintModel++) {
403 : : mModelBuff.mpaModelData[lintModel].mintModelHandle =
404 : : lpaModels[lintModel].mintModelHandle;
405 : : mModelBuff.mpaModelData[lintModel].mintModelType =
406 : : lpaModels[lintModel].mintModelType;
407 : : mModelBuff.mpaModelData[lintModel].mintModelOwner =
408 : : lpaModels[lintModel].mintModelOwner;
409 : : }
410 : : return eSuccess;
411 : : }*/
412 : :
413 : 0 : UnsignedInt32 CCubitFile::IsModel(HModel xintModel)
414 : : {
415 : : UnsignedInt32 lintIndex;
416 [ # # ]: 0 : if(mWriteContents.mintNumModels)
417 [ # # ]: 0 : return FindModel(xintModel, mpaWriteModels, mWriteContents.mintNumModels, lintIndex);
418 [ # # ]: 0 : else if(mReadContents.mintNumModels)
419 [ # # ]: 0 : return FindModel(xintModel, mpaReadModels, mReadContents.mintNumModels, lintIndex);
420 : 0 : return 0; // failure
421 : : }
422 : :
423 : 0 : UnsignedInt32 CCubitFile::GetReadModelLength(HModel xintModel,
424 : : UnsignedInt32& xintLength)
425 : : // Looks up the length of the data block in the cubit filr for the requested
426 : : // model. Returns success if the model is found, otherwise an error is returned.
427 : : {
428 : : UnsignedInt32 lintIndex;
429 [ # # ][ # # ]: 0 : if(FindModel(xintModel, mpaReadModels, mReadContents.mintNumModels, lintIndex)) {
430 : 0 : xintLength = mpaReadModels[lintIndex].mintModelLength;
431 : 0 : return eSuccess;
432 : : }
433 : : else {
434 : 0 : xintLength = 0;
435 : 0 : return eNotFound;
436 : : }
437 : : }
438 : :
439 : 0 : UnsignedInt32 CCubitFile::CreateModel(EModelType xeModelType, HModel& xintModel)
440 : : // Define a new model in the temp file.
441 : : {
442 [ # # ]: 0 : if(!mpWriteFile) return eFileWriteError;
443 : :
444 : : // Allocate a new bigger model table, copy the existing table (if any)
445 : : // into the new one and then replace the old one.
446 : : SCubitFileModelEntry* lpaModels =
447 [ # # ]: 0 : new SCubitFileModelEntry[mWriteContents.mintNumModels + 1];
448 [ # # ]: 0 : if(!lpaModels) return eMemoryError;
449 [ # # ]: 0 : if(mpaWriteModels) {
450 : : memcpy(lpaModels, mpaWriteModels,
451 : 0 : sizeof(SCubitFileModelEntry) * mWriteContents.mintNumModels);
452 [ # # ]: 0 : delete [] mpaWriteModels;
453 : : }
454 : 0 : mpaWriteModels = lpaModels;
455 : :
456 : : // Initialize the new model's table entry.
457 : 0 : mpaWriteModels[mWriteContents.mintNumModels].mintModelHandle =
458 : 0 : xintModel;// = mintNextModelID++;
459 : 0 : mpaWriteModels[mWriteContents.mintNumModels].mintModelOffset = 0;
460 : 0 : mpaWriteModels[mWriteContents.mintNumModels].mintModelLength = 0;
461 : 0 : mpaWriteModels[mWriteContents.mintNumModels].mintModelType = xeModelType;
462 : 0 : mpaWriteModels[mWriteContents.mintNumModels].mintModelOwner = 0;
463 : 0 : mpaWriteModels[mWriteContents.mintNumModels].mintModel64bitOSPad = 0;
464 : 0 : mWriteContents.mintNumModels++;
465 : :
466 : 0 : return eSuccess;
467 : : }
468 : :
469 : 0 : UnsignedInt32 CCubitFile::DeleteModel(HModel xintModel)
470 : : // Flag an model that exists in the read file not to be copied into the write file.
471 : : {
472 [ # # ][ # # ]: 0 : if(!mpWriteFile) return eFileWriteError;
473 : :
474 : : // Flag the model in the old file as marked for deletion.
475 : : UnsignedInt32 lintIndex;
476 [ # # ][ # # ]: 0 : if(!FindModel(xintModel, mpaReadModels, mReadContents.mintNumModels, lintIndex))
477 : 0 : return eNotFound;
478 [ # # ]: 0 : if(mpaReadModelStat[lintIndex] == eStatWritten)
479 : 0 : return eOrderError;
480 : 0 : mpaReadModelStat[lintIndex] = eStatDelete;
481 : :
482 : : // Remove the model from the write file's table and close up the position in
483 : : // the model table (if applicable).
484 [ # # ][ # # ]: 0 : if(FindModel(xintModel, mpaWriteModels, mWriteContents.mintNumModels, lintIndex)) {
485 : 0 : mWriteContents.mintNumModels--;
486 [ # # ][ # # ]: 0 : if(mWriteContents.mintNumModels &&
487 : 0 : (lintIndex < mWriteContents.mintNumModels)) {
488 [ # # ]: 0 : for(UnsignedInt32 lintCopyTo = lintIndex; lintCopyTo <
489 : : mWriteContents.mintNumModels; lintCopyTo++) {
490 : 0 : memcpy(&mpaWriteModels[lintCopyTo],
491 : 0 : &mpaWriteModels[lintCopyTo + 1],
492 : 0 : sizeof(SCubitFileModelEntry));
493 : : }
494 : : }
495 : : }
496 : :
497 : : // Find any models that have the deleted model as their owner and reset
498 : : // the owner to no owner (0).
499 [ # # ]: 0 : if(mWriteContents.mintNumModels) {
500 [ # # ]: 0 : for(UnsignedInt32 lintModel = 0; lintModel <
501 : : mWriteContents.mintNumModels; lintModel++) {
502 [ # # ]: 0 : if(mpaWriteModels[lintModel].mintModelOwner == xintModel)
503 : 0 : mpaWriteModels[lintModel].mintModelOwner = 0;
504 : : }
505 : : }
506 : :
507 : : // Delete any meta-data that belonged with the deleted model.
508 [ # # ]: 0 : mpMetaData->ClearMetaDataForID(xintModel);
509 : :
510 : 0 : return eSuccess;
511 : : }
512 : :
513 : 0 : UnsignedInt32 CCubitFile::GetModelOwner(HModel xintModel, HModel& xintOwner)
514 : : // Return the owning model of the passed model.
515 : : {
516 : : // Flag the model in the old file as marked for deletion.
517 : : UnsignedInt32 lintIndex;
518 [ # # ][ # # ]: 0 : if(!FindModel(xintModel, mpaWriteModels, mWriteContents.mintNumModels, lintIndex))
519 : 0 : return eNotFound;
520 : 0 : xintOwner = mpaWriteModels[lintIndex].mintModelOwner;
521 : 0 : return eSuccess;
522 : : }
523 : :
524 : 0 : UnsignedInt32 CCubitFile::SetModelOwner(HModel xintModel, HModel xintOwner)
525 : : // Set the owning model for the passed model.
526 : : {
527 : : // Flag the model in the old file as marked for deletion.
528 : : UnsignedInt32 lintIndex;
529 [ # # ][ # # ]: 0 : if(xintOwner && // don't allow the model to have a non-existant owner.
[ # # ]
530 [ # # ]: 0 : !FindModel(xintOwner, mpaWriteModels, mWriteContents.mintNumModels, lintIndex))
531 : 0 : return eNotFound;
532 [ # # ][ # # ]: 0 : if(!FindModel(xintModel, mpaWriteModels, mWriteContents.mintNumModels, lintIndex))
533 : 0 : return eNotFound;
534 : 0 : mpaWriteModels[lintIndex].mintModelOwner = xintOwner;
535 : 0 : return eSuccess;
536 : : }
537 : :
538 : 0 : UnsignedInt32 CCubitFile::FindModel(HModel xintModel,
539 : : SCubitFileModelEntry* xpaModels,
540 : : UnsignedInt32 xintNumModels,
541 : : UnsignedInt32& xintIndex)
542 : : // Determine the index of the passed model handle in the passed model table.
543 : : // Private function, return true/false, no exceptions thrown.
544 : : {
545 [ # # ]: 0 : if(xintNumModels) {
546 [ # # ]: 0 : for(UnsignedInt32 lintMod = 0; lintMod < xintNumModels; lintMod++) {
547 [ # # ]: 0 : if(xpaModels[lintMod].mintModelHandle == xintModel) {
548 : 0 : xintIndex = lintMod;
549 : 0 : return 1; // success
550 : : }
551 : : }
552 : : }
553 : 0 : return 0; // failure
554 : : }
555 : :
556 : 0 : void CCubitFile::WriteModelTable()
557 : : // Write (or rewrite) the model table to the write file.
558 : : {
559 [ # # ][ # # ]: 0 : if(!mpWriteFile) throw eFileWriteError;
560 : :
561 [ # # ]: 0 : if(!mWriteContents.mintNumModels) return; // no models... nothing to do!
562 : :
563 [ # # ][ # # ]: 0 : CIOWrapper lIO(mpWriteFile.file());
564 : :
565 : : // Write the model table, if the number of models has increased, write the
566 : : // table to a new location in the file, otherwise reuse the previous
567 : : // table's file space.
568 [ # # ]: 0 : if(mWriteContents.mintNumModels > mintWriteBuffNumModels) {
569 : 0 : mintWriteBuffNumModels = mWriteContents.mintNumModels;
570 [ # # ]: 0 : mWriteContents.mintModelTableOffset = lIO.BeginWriteBlock();
571 : : }
572 : : else
573 [ # # ]: 0 : lIO.BeginRewriteBlock(mWriteContents.mintModelTableOffset, 0);
574 : : lIO.Write((UnsignedInt32*)mpaWriteModels,
575 [ # # ]: 0 : mWriteContents.mintNumModels * mintSizeOfModel);
576 [ # # ]: 0 : lIO.EndWriteBlock();
577 : :
578 : : // Rewrite the contents header to reflect any model table changes.
579 [ # # ]: 0 : lIO.BeginRewriteBlock(4, 0);
580 [ # # ]: 0 : lIO.Write((UnsignedInt32*)&mWriteContents, mintSizeOfContents);
581 [ # # ][ # # ]: 0 : lIO.EndWriteBlock();
582 : : }
583 : :
584 : 0 : void CCubitFile::CopyModel(UnsignedInt32 xintReadOffset,
585 : : UnsignedInt32& xintWriteOffset,
586 : : UnsignedInt32 xintLength,
587 : : FILE* xpReadFile, FILE* xpWriteFile)
588 : : // Copy a model from one file to another. The copied model is byte identical
589 : : // to the original.
590 : : {
591 : : // Create a 16 kilobyte memory buffer to try to improve copy IO efficiency
592 : : // over a byte-per-byte copy.
593 [ # # ]: 0 : char* lpachrCopyBuffer = new char[0x4000]; //16KB
594 [ # # ]: 0 : if(!lpachrCopyBuffer)
595 : 0 : throw eMemoryError;
596 : :
597 : : // Position the files pointers for the copy.
598 [ # # ]: 0 : CIOWrapper lReadIO(xpReadFile);
599 [ # # ][ # # ]: 0 : CIOWrapper lWriteIO(xpWriteFile);
600 [ # # ]: 0 : lReadIO.BeginReadBlock(xintReadOffset);
601 [ # # ]: 0 : xintWriteOffset = lWriteIO.BeginWriteBlock();
602 : :
603 : : // Copy the models 16K at a time.
604 : 0 : UnsignedInt32 lintRemaining = xintLength;
605 : 0 : UnsignedInt32 lintCopyBytes = 0x4000;
606 [ # # ]: 0 : while(lintRemaining) {
607 [ # # ]: 0 : if(lintRemaining > 0x4000) // More than 16K left, copy 16K.
608 : 0 : lintRemaining -= 0x4000;
609 : : else { // 16K or less left, copy all of what's left.
610 : 0 : lintCopyBytes = lintRemaining;
611 : 0 : lintRemaining = 0;
612 : : }
613 [ # # ]: 0 : lReadIO.Read(lpachrCopyBuffer, lintCopyBytes);
614 [ # # ]: 0 : lWriteIO.Write(lpachrCopyBuffer, lintCopyBytes);
615 : : }
616 : :
617 : : // Make sure the copy was complete and free the buffer.
618 [ # # ]: 0 : lReadIO.EndReadBlock();
619 [ # # ][ # # ]: 0 : if(lWriteIO.EndWriteBlock() != xintLength)
620 : 0 : throw eCorruptBlock;
621 [ # # ][ # # ]: 0 : delete [] lpachrCopyBuffer;
622 : 0 : }
623 : :
624 : :
625 : : ///////////////////////////////////////////////////////////////////////////////
626 : : // Geometry Model Read/Write
627 : : ///////////////////////////////////////////////////////////////////////////////
628 : :
629 : 0 : UnsignedInt32 CCubitFile::BeginWriteGeomModel(HModel xintGeomModel,
630 : : const char* xstrGeomFile)
631 : : // Copy an external geometry file into the cubit file as a geometry model.
632 : : {
633 [ # # ][ # # ]: 0 : if(!mpWriteFile) return eFileWriteError;
634 : :
635 : : // Try to open the geometry model file for reading.
636 [ # # ][ # # ]: 0 : CubitFile lpGeomFile(xstrGeomFile, "rb");
[ # # # # ]
637 [ # # ][ # # ]: 0 : if(!lpGeomFile)
638 : 0 : return eFileReadError;
639 : :
640 : : // Determine the size of the geometry file and then copy it into the
641 : : // cubit file.
642 : 0 : EErrorCode leReturn = eSuccess;
643 : : try {
644 : : UnsignedInt32 lintReadIndex, lintWriteIndex;
645 : : // Locate the model's index in the write contents and make sure it is
646 : : // not an FEA model.
647 [ # # ]: 0 : if(!FindModel(xintGeomModel, mpaWriteModels,
648 [ # # ]: 0 : mWriteContents.mintNumModels, lintWriteIndex))
649 : 0 : throw eNotFound;
650 [ # # ]: 0 : if(mpaWriteModels[lintWriteIndex].mintModelType == eFEModel)
651 : 0 : throw eNotFound;
652 : : // Locate the model's index in the read contents, if possible, and
653 : : // make sure the model has not already been written or deleted, and
654 : : // then mark it written.
655 [ # # ]: 0 : if(FindModel(xintGeomModel, mpaReadModels,
656 [ # # ]: 0 : mReadContents.mintNumModels, lintReadIndex)) {
657 [ # # ]: 0 : if(mpaReadModelStat[lintReadIndex] != eStatNotWritten)
658 : 0 : throw eOrderError;
659 : 0 : mpaReadModelStat[lintReadIndex] = eStatWritten;
660 : : }
661 : :
662 : : // Measure the length of the geometry model file and then copy it into
663 : : // to cubit file.
664 [ # # ][ # # ]: 0 : if(NCubitFile::SetLocation(lpGeomFile.file(), 0, SEEK_END))
[ # # ]
665 : 0 : throw CCubitFile::eFileSeekError;
666 [ # # ][ # # ]: 0 : UnsignedInt32 lintGeomLength = GetLocation(lpGeomFile.file());
667 : 0 : CopyModel(0, mpaWriteModels[lintWriteIndex].mintModelOffset,
668 [ # # ][ # # ]: 0 : lintGeomLength, lpGeomFile.file(), mpWriteFile.file());
[ # # ]
669 : 0 : mpaWriteModels[lintWriteIndex].mintModelLength = lintGeomLength;
670 : : }
671 : 0 : catch(EErrorCode xeErrorCode) { leReturn = xeErrorCode; }
672 [ # # ]: 0 : catch(...) { leReturn = eUnknownError; }
673 : :
674 [ # # ]: 0 : return leReturn;
675 : : }
676 : :
677 : 0 : UnsignedInt32 CCubitFile::EndWriteGeomModel()
678 : : // The formal end to a geometry model write.
679 : : {
680 : 0 : return eSuccess;
681 : : }
682 : :
683 : 0 : UnsignedInt32 CCubitFile::BeginReadGeomModel(HModel xintGeomModel,
684 : : FILE* xpGeomFile)
685 : : // Copy an geometry model out of the cubit file into an external geometry file.
686 : : {
687 [ # # ]: 0 : if(!mpReadFile) return eFileReadError;
688 [ # # ]: 0 : if(!xpGeomFile) return eFileWriteError;
689 : :
690 : 0 : UnsignedInt32 lintStartFilePos = GetLocation(xpGeomFile);
691 : :
692 : : // Determine the size of the geometry file and then copy it into the
693 : : // cubit file.
694 : 0 : EErrorCode leReturn = eSuccess;
695 : : try {
696 : : UnsignedInt32 lintReadIndex, lintWriteOffset;
697 : : // Locate the model's index in the read contents and make sure it is
698 : : // not an FEA model.
699 [ # # ]: 0 : if(!FindModel(xintGeomModel, mpaReadModels,
700 [ # # ]: 0 : mReadContents.mintNumModels, lintReadIndex))
701 : 0 : throw eNotFound;
702 [ # # ]: 0 : if(mpaReadModels[lintReadIndex].mintModelType == eFEModel)
703 : 0 : throw eNotFound;
704 : :
705 : : // Copy the geometry model file out of the cubit file.
706 : 0 : CopyModel(mpaReadModels[lintReadIndex].mintModelOffset,
707 : 0 : lintWriteOffset, mpaReadModels[lintReadIndex].mintModelLength,
708 [ # # ][ # # ]: 0 : mpReadFile.file(), xpGeomFile);
709 : : }
710 : 0 : catch(EErrorCode xeErrorCode) { leReturn = xeErrorCode; }
711 : 0 : catch(...) { leReturn = eUnknownError; }
712 : :
713 : 0 : NCubitFile::SetLocation(xpGeomFile, lintStartFilePos, SEEK_SET);
714 [ # # ]: 0 : return leReturn;
715 : : }
716 : :
717 : 0 : UnsignedInt32 CCubitFile::EndReadGeomModel()
718 : : // The formal end to a geometry model read.
719 : : {
720 : 0 : return eSuccess;
721 : : }
722 : :
723 : :
724 : 0 : UnsignedInt32 CCubitFile::BeginWriteModel(HModel xintModelId, EModelType type,
725 : : FILE*& writeable_file)
726 : : {
727 : : // Let's not return a FILE* until we know it's going to be OK to write to.
728 : 0 : writeable_file = NULL;
729 : :
730 [ # # ]: 0 : if(!mpWriteFile)
731 : 0 : return eFileWriteError;
732 : :
733 : 0 : EErrorCode leReturn = eSuccess;
734 : : try
735 : : {
736 : : UnsignedInt32 lintReadIndex, lintWriteIndex;
737 : : // Locate the model's index in the write contents and make sure it is
738 : : // the right kind of model.
739 [ # # ]: 0 : if(!FindModel(xintModelId,
740 : : mpaWriteModels,
741 : : mWriteContents.mintNumModels,
742 [ # # ]: 0 : lintWriteIndex))
743 : 0 : throw eNotFound;
744 : :
745 [ # # ]: 0 : if(mpaWriteModels[lintWriteIndex].mintModelType != type)
746 : 0 : throw eNotFound;
747 : :
748 : : // Locate the model's index in the read contents, if possible, and
749 : : // make sure the model has not already been written or deleted, and
750 : : // then mark it as being written.
751 [ # # ]: 0 : if(FindModel(xintModelId, mpaReadModels,
752 [ # # ]: 0 : mReadContents.mintNumModels, lintReadIndex))
753 : : {
754 [ # # ]: 0 : if(mpaReadModelStat[lintReadIndex] != eStatNotWritten)
755 : 0 : throw eOrderError;
756 : 0 : mpaReadModelStat[lintReadIndex] = eStatWriting;
757 : : }
758 : :
759 : : // Move the FILE* to the correct write position so the FILE*
760 : : // can be written to directly. From CopyFile, it looks like the
761 : : // correct location is the end of the file.
762 [ # # ][ # # ]: 0 : if (NCubitFile::SetLocation(mpWriteFile.file(), 0, SEEK_END))
[ # # ]
763 : 0 : throw eFileSeekError;
764 : :
765 : : // Save our current FILE* position so we can detect the size of
766 : : // data written to the model.
767 [ # # ][ # # ]: 0 : mpaWriteModels[lintWriteIndex].mintModelOffset = GetLocation(mpWriteFile.file());
768 : :
769 : : // set the FILE*
770 [ # # ]: 0 : writeable_file = mpWriteFile.file();
771 : : }
772 : 0 : catch(EErrorCode xeErrorCode)
773 : 0 : { leReturn = xeErrorCode; }
774 : 0 : catch(...)
775 : 0 : { leReturn = eUnknownError; }
776 : :
777 [ # # ]: 0 : return leReturn;
778 : : }
779 : :
780 : 0 : UnsignedInt32 CCubitFile::EndWriteModel(HModel xintModelId)
781 : : {
782 [ # # ][ # # ]: 0 : if (!mpWriteFile)
783 : 0 : return eFileWriteError;
784 : :
785 : : // Find the model's write record
786 : : UnsignedInt32 lintWriteIndex;
787 [ # # ]: 0 : if(!FindModel(xintModelId,
788 : : mpaWriteModels,
789 : : mWriteContents.mintNumModels,
790 [ # # ]: 0 : lintWriteIndex))
791 : 0 : return eNotFound;
792 : :
793 : : // Make sure we saved the start position
794 [ # # ]: 0 : if (mpaWriteModels[lintWriteIndex].mintModelOffset == 0)
795 : 0 : return eOrderError;
796 : :
797 : : // Get the end of the FILE.
798 [ # # ][ # # ]: 0 : if (NCubitFile::SetLocation(mpWriteFile.file(), 0, SEEK_END))
[ # # ]
799 : 0 : return eFileSeekError;
800 [ # # ][ # # ]: 0 : UnsignedInt32 cur_pos = GetLocation(mpWriteFile.file());
801 : :
802 : : // See how many bytes that is past our saved position.
803 : 0 : UnsignedInt32 size_in_bytes = cur_pos - mpaWriteModels[lintWriteIndex].mintModelOffset;
804 : :
805 : : // Locate the model's index in the read contents, if possible, and
806 : : // make sure the model has not already been written or deleted, and
807 : : // then mark it as written.
808 : : UnsignedInt32 lintReadIndex;
809 [ # # ]: 0 : if(FindModel(xintModelId, mpaReadModels,
810 [ # # ]: 0 : mReadContents.mintNumModels, lintReadIndex))
811 : : {
812 [ # # ]: 0 : if(mpaReadModelStat[lintReadIndex] != eStatWriting)
813 : 0 : throw eOrderError;
814 : 0 : mpaReadModelStat[lintReadIndex] = eStatWritten;
815 : : }
816 : :
817 : : // Save the size to the model header.
818 : 0 : mpaWriteModels[lintWriteIndex].mintModelLength = size_in_bytes;
819 : :
820 : 0 : return eSuccess;
821 : : }
822 : :
823 : : // Returns a FILE* that can be read from. The FILE* will NOT return EOF
824 : : // at the end of the data...the reader should not go GetReadModelLength()
825 : : // bytes beyond the current FILE* position. You should copy the contents
826 : : // to another FILE if this is an issue for the reader.
827 : 0 : UnsignedInt32 CCubitFile::BeginReadModel(HModel xintModelId, EModelType type,
828 : : FILE*& f)
829 : : {
830 : 0 : f = NULL;
831 : :
832 [ # # ]: 0 : if(!mpReadFile)
833 : 0 : return eFileReadError;
834 : :
835 : : // Determine the size of the geometry file and then copy it into the
836 : : // cubit file.
837 : 0 : EErrorCode leReturn = eSuccess;
838 : : try
839 : : {
840 : : UnsignedInt32 lintReadIndex;
841 : : // Locate the model's index in the read contents and make sure it is
842 : : // an assembly model.
843 [ # # ]: 0 : if(!FindModel(xintModelId, mpaReadModels,
844 [ # # ]: 0 : mReadContents.mintNumModels, lintReadIndex))
845 : 0 : throw eNotFound;
846 [ # # ]: 0 : if(mpaReadModels[lintReadIndex].mintModelType != type)
847 : 0 : throw eNotFound;
848 : :
849 : : // Set the read pointer to the correct location
850 [ # # ][ # # ]: 0 : NCubitFile::SetLocation(mpReadFile.file(), mpaReadModels[lintReadIndex].mintModelOffset, SEEK_SET);
851 : :
852 : : // Set the FILE*
853 [ # # ]: 0 : f = mpReadFile.file();
854 : : }
855 : 0 : catch(EErrorCode xeErrorCode)
856 : 0 : { leReturn = xeErrorCode; }
857 : 0 : catch(...)
858 : 0 : { leReturn = eUnknownError; }
859 : :
860 [ # # ]: 0 : return leReturn;
861 : : }
862 : :
863 : 0 : UnsignedInt32 CCubitFile::EndReadModel()
864 : : {
865 : 0 : return eSuccess;
866 : : }
867 : :
868 : :
869 : : ///////////////////////////////////////////////////////////////////////////////
870 : : // FEA Model Read/Write
871 : : ///////////////////////////////////////////////////////////////////////////////
872 : :
873 : 0 : UnsignedInt32 CCubitFile::BeginWriteFEModel(HModel xintFEModel,
874 : : UnsignedInt32 xintGeomCount,
875 : : UnsignedInt32 xintGroupCount,
876 : : UnsignedInt32 xintBlockCount,
877 : : UnsignedInt32 xintNodeSetCount,
878 : : UnsignedInt32 xintSideSetCount)
879 : : // Prepares the file for the writing of a FEA model. After this call there
880 : : // should be no other write oprations on the file not associated with the
881 : : // writing of the FEA model until a matching call is made to EndWriteFEModel.
882 : : // RETURNS: 0 on success, other values indicate error code.
883 : : {
884 : : try {
885 [ # # ][ # # ]: 0 : if(!mpWriteFile) throw eFileWriteError;
886 [ # # ]: 0 : if(mpWriteFEModel) throw eOrderError;
887 : :
888 : : // Write the model table first to try to guarentee that it will be
889 : : // at the beginning of the file.
890 [ # # ]: 0 : WriteModelTable();
891 : :
892 : : // Lookup the requested model in the model table and make sure it is
893 : : // an FEA model.
894 [ # # ]: 0 : if(!FindModel(xintFEModel, mpaWriteModels, mWriteContents.mintNumModels,
895 [ # # ]: 0 : mintFEModelIndex))
896 : 0 : throw eNotFound;
897 [ # # ]: 0 : if(mpaWriteModels[mintFEModelIndex].mintModelType != eFEModel)
898 : 0 : throw eNotFound;
899 : :
900 : : // Create the object that manages FEA model file transactions and have
901 : : // it begin its model write.
902 [ # # ]: 0 : mpWriteFEModel = new CFEModel();
[ # # # # ]
903 [ # # ]: 0 : if(!mpWriteFEModel)
904 : 0 : throw eMemoryError;
905 : :
906 : 0 : mpaWriteModels[mintFEModelIndex].mintModelOffset =
907 : : mpWriteFEModel->InitWrite(mpWriteFile.file(), xintGeomCount, xintGroupCount,
908 [ # # ][ # # ]: 0 : xintBlockCount, xintNodeSetCount, xintSideSetCount);
909 : 0 : return eSuccess;
910 : : }
911 : 0 : catch(EErrorCode xeErrorCode) { return xeErrorCode; }
912 : 0 : catch(...) { return eUnknownError; }
913 : : }
914 : :
915 : : // Try to write the nodes for the passed geometry index/ID to the writable file
916 : 0 : UnsignedInt32 CCubitFile::WriteNodes(UnsignedInt32 xintIndex,
917 : : UnsignedInt32 xintGeomID,
918 : : UnsignedInt32 xintNodeCount,
919 : : UnsignedInt32 *xpaintNodeIDs,
920 : : double *xpadblX,
921 : : double *xpadblY,
922 : : double *xpadblZ)
923 : : {
924 : : try
925 : : {
926 [ # # ]: 0 : if(!mpWriteFEModel)
927 : 0 : throw eOrderError;
928 : : mpWriteFEModel->WriteNodes(xintIndex, xintGeomID,
929 : : xintNodeCount, xpaintNodeIDs,
930 [ # # ]: 0 : xpadblX, xpadblY, xpadblZ);
931 : : }
932 : 0 : catch(EErrorCode xeErrorCode) { return xeErrorCode; }
933 : 0 : catch(...) { return eUnknownError; }
934 [ # # ]: 0 : return eSuccess;
935 : : }
936 : :
937 : 0 : UnsignedInt32 CCubitFile::WriteElems(UnsignedInt32 xintIndex,
938 : : UnsignedInt32 xintNumTypes,
939 : : SElemData* xpaElemData)
940 : : // Try to write the element connectivity for the passed geometry index/ID
941 : : // to the writable file.
942 : : {
943 : : try {
944 [ # # ]: 0 : if(!mpWriteFEModel)
945 : 0 : throw eOrderError;
946 [ # # ]: 0 : mpWriteFEModel->WriteElems(xintIndex, xintNumTypes, xpaElemData);
947 [ # # ]: 0 : return eSuccess;
948 : : }
949 : 0 : catch(EErrorCode xeErrorCode) { return xeErrorCode; }
950 : 0 : catch(...) { return eUnknownError; }
951 : : }
952 : :
953 : 0 : UnsignedInt32 CCubitFile::WriteGroup(UnsignedInt32 xintIndex,
954 : : UnsignedInt32 xintGroupID,
955 : : UnsignedInt32 xintGroupType,
956 : : ConstCharPtr xpachrGroupName,
957 : : UnsignedInt32 xintNumTypes,
958 : : SGroupData* xpaGroupData)
959 : : // Try to write the membership of the passed group index to the writable file.
960 : : // RETURNS: 0 on success, other values indicate error code.
961 : : {
962 : : try {
963 [ # # ]: 0 : if(!mpWriteFEModel)
964 : 0 : throw eOrderError;
965 : : mpWriteFEModel->WriteGroup(xintIndex, xintGroupID,
966 [ # # ]: 0 : xintGroupType, xpachrGroupName, xintNumTypes, xpaGroupData);
967 [ # # ]: 0 : return eSuccess;
968 : : }
969 : 0 : catch(EErrorCode xeErrorCode) { return xeErrorCode; }
970 : 0 : catch(...) { return eUnknownError; }
971 : : }
972 : :
973 : 0 : UnsignedInt32 CCubitFile::WriteBlock(UnsignedInt32 xintIndex,
974 : : UnsignedInt32 xintBlockID,
975 : : int unique_id,
976 : : UnsignedInt32 xintBlockType,
977 : : UnsignedInt32 xintBlockColor,
978 : : UnsignedInt32 xintMixedElemType,
979 : : UnsignedInt32 xintDefPyramidType,
980 : : UnsignedInt32 xintMaterialID,
981 : : UnsignedInt32 xintBlockDimension,
982 : : UnsignedInt32 xintNumTypes,
983 : : SBlockData* xpaBlockData,
984 : : UnsignedInt32 xintAttributeOrder,
985 : : double* xpadblAttributes)
986 : : // Try to write the membership of the passed group index to the writable file.
987 : : // RETURNS: 0 on success, other values indicate error code.
988 : : {
989 : : try {
990 [ # # ]: 0 : if(!mpWriteFEModel)
991 : 0 : throw eOrderError;
992 : : mpWriteFEModel->WriteBlock(xintIndex, xintBlockID, unique_id, xintBlockType,
993 : : xintBlockColor, xintMixedElemType, xintDefPyramidType,
994 : : xintMaterialID, xintBlockDimension, xintNumTypes, xpaBlockData,
995 [ # # ]: 0 : xintAttributeOrder, xpadblAttributes);
996 [ # # ]: 0 : return eSuccess;
997 : : }
998 : 0 : catch(EErrorCode xeErrorCode) { return xeErrorCode; }
999 : 0 : catch(...) { return eUnknownError; }
1000 : : }
1001 : :
1002 : 0 : UnsignedInt32 CCubitFile::WriteNodeSet(UnsignedInt32 xintIndex,
1003 : : UnsignedInt32 xintNodeSetID,
1004 : : int unique_id,
1005 : : UnsignedInt32 xintColor,
1006 : : UnsignedInt32 xintPointSymbol,
1007 : : UnsignedInt32 xintNumTypes,
1008 : : SNodeSetData* xpaNodeSetData,
1009 : : const std::vector<char>& bcdata)
1010 : : // Try to write the membership of the passed group index to the writable file.
1011 : : // RETURNS: 0 on success, other values indicate error code.
1012 : : {
1013 : : try {
1014 [ # # ]: 0 : if(!mpWriteFEModel)
1015 : 0 : throw eOrderError;
1016 : : mpWriteFEModel->WriteNodeSet(xintIndex, xintNodeSetID, unique_id, xintColor,
1017 [ # # ]: 0 : xintPointSymbol, xintNumTypes, xpaNodeSetData, bcdata);
1018 [ # # ]: 0 : return eSuccess;
1019 : : }
1020 : 0 : catch(EErrorCode xeErrorCode) { return xeErrorCode; }
1021 : 0 : catch(...) { return eUnknownError; }
1022 : : }
1023 : :
1024 : 0 : UnsignedInt32 CCubitFile::WriteSideSet_11(UnsignedInt32 xintIndex,
1025 : : UnsignedInt32 xintSideSetID,
1026 : : int unique_id,
1027 : : UnsignedInt32 xintColor,
1028 : : UnsignedInt32 xintUseShells,
1029 : : UnsignedInt32 xintNumTypes,
1030 : : SSideSetData_11* xpaSideSetData,
1031 : : UnsignedInt32 xintNumDistFact,
1032 : : double* xpadblDistribution,
1033 : : const std::vector<char>& bcdata)
1034 : : // Try to write the membership of the passed group index to the writable file.
1035 : : // RETURNS: 0 on success, other values indicate error code.
1036 : : {
1037 : : try {
1038 [ # # ]: 0 : if(!mpWriteFEModel)
1039 : 0 : throw eOrderError;
1040 : : mpWriteFEModel->WriteSideSet_11(xintIndex, xintSideSetID, unique_id, xintColor,
1041 : : xintUseShells, xintNumTypes, xpaSideSetData, xintNumDistFact,
1042 [ # # ]: 0 : xpadblDistribution, bcdata);
1043 [ # # ]: 0 : return eSuccess;
1044 : : }
1045 : 0 : catch(EErrorCode xeErrorCode) { return xeErrorCode; }
1046 : 0 : catch(...) { return eUnknownError; }
1047 : : }
1048 : :
1049 : 0 : UnsignedInt32 CCubitFile::EndWriteFEModel()
1050 : : // Designate the end of writing a FEA model and free any memory allocated for
1051 : : // the write operations and update the file contents header.
1052 : : // RETURNS: 0 on success, other values indicate error code.
1053 : : {
1054 : : try {
1055 [ # # ]: 0 : if(!mpWriteFEModel)
1056 : 0 : throw eOrderError;
1057 : 0 : mpaWriteModels[mintFEModelIndex].mintModelLength =
1058 [ # # ]: 0 : mpWriteFEModel->EndWrite();
1059 [ # # ][ # # ]: 0 : delete mpWriteFEModel;
1060 : 0 : mpWriteFEModel = NULL;
1061 : :
1062 : : UnsignedInt32 lintReadIndex;
1063 [ # # ]: 0 : if(FindModel(mpaWriteModels[mintFEModelIndex].mintModelHandle,
1064 [ # # ]: 0 : mpaReadModels, mReadContents.mintNumModels, lintReadIndex))
1065 : 0 : mpaReadModelStat[lintReadIndex] = eStatWritten;
1066 : :
1067 [ # # ]: 0 : return eSuccess;
1068 : : }
1069 : 0 : catch(EErrorCode xeErrorCode) { return xeErrorCode; }
1070 : 0 : catch(...) { return eUnknownError; }
1071 : : }
1072 : :
1073 : : //-----------------------------------------------------------------------------
1074 : :
1075 : 0 : UnsignedInt32 CCubitFile::BeginReadFEModel(HModel xintFEModel,
1076 : : UnsignedInt32& xintGeomCount,
1077 : : UnsignedInt32& xintGroupCount,
1078 : : UnsignedInt32& xintBlockCount,
1079 : : UnsignedInt32& xintNodeSetCount,
1080 : : UnsignedInt32& xintSideSetCount)
1081 : : // Prepares the file for the reading of a FEA model. After this call there
1082 : : // should be no other read oprations on the file not associated with the
1083 : : // reading of the FEA model until a matching call is made to EndReadFEModel.
1084 : : // RETURNS: 0 on success, other values indicate error code.
1085 : : {
1086 : : try {
1087 [ # # ][ # # ]: 0 : if(!mpReadFile) throw eFileReadError;
1088 [ # # ]: 0 : if(mpReadFEModel) throw eOrderError;
1089 : :
1090 : : UnsignedInt32 lintIndex;
1091 [ # # ]: 0 : if(!FindModel(xintFEModel, mpaReadModels, mReadContents.mintNumModels,
1092 [ # # ]: 0 : lintIndex))
1093 : 0 : throw eNotFound;
1094 [ # # ]: 0 : if(mpaReadModels[lintIndex].mintModelType != eFEModel)
1095 : 0 : throw eNotFound;
1096 : :
1097 [ # # ]: 0 : mpReadFEModel = new CFEModel();
[ # # # # ]
1098 [ # # ]: 0 : if(!mpReadFEModel) throw eMemoryError;
1099 : :
1100 : 0 : mpReadFEModel->InitRead(mpReadFile.file(), mpaReadModels[lintIndex].mintModelOffset,
1101 : : xintGeomCount, xintGroupCount,
1102 [ # # ][ # # ]: 0 : xintBlockCount, xintNodeSetCount, xintSideSetCount);
1103 : 0 : return eSuccess;
1104 : : }
1105 : 0 : catch(EErrorCode xeErrorCode) { return xeErrorCode; }
1106 : 0 : catch(...) { return eUnknownError; }
1107 : : }
1108 : :
1109 : 0 : UnsignedInt32 CCubitFile::ReadNodes(UnsignedInt32 xintIndex,
1110 : : UnsignedInt32& xintGeomID,
1111 : : UnsignedInt32& xintNodeCount,
1112 : : UnsignedInt32*& xpaintNodeIDs,
1113 : : double*& xpadblX,
1114 : : double*& xpadblY,
1115 : : double*& xpadblZ)
1116 : : // Try to read the nodes for the passed geometry index/ID from the
1117 : : // read-only file.
1118 : : // RETURNS: 0 on success, other values indicate error code.
1119 : : {
1120 : : UnsignedInt32 lintErrorCode;
1121 : : try {
1122 [ # # ]: 0 : if(!mpReadFEModel)
1123 : 0 : throw eOrderError;
1124 : : mpReadFEModel->ReadNodes(xintIndex, xintGeomID,
1125 [ # # ]: 0 : xintNodeCount, xpaintNodeIDs, xpadblX, xpadblY, xpadblZ);
1126 : 0 : return eSuccess;
1127 : : }
1128 : 0 : catch(EErrorCode xeErrorCode) {
1129 : 0 : lintErrorCode = xeErrorCode;
1130 : : }
1131 : 0 : catch(...) {
1132 : 0 : lintErrorCode = eUnknownError;
1133 : : }
1134 : 0 : xintNodeCount = 0;
1135 : 0 : xpaintNodeIDs = NULL;
1136 : 0 : xpadblX = xpadblY = xpadblZ = NULL;
1137 [ # # ]: 0 : return lintErrorCode;
1138 : : }
1139 : :
1140 : 0 : UnsignedInt32 CCubitFile::ReadElems(HModel meshModelId,
1141 : : UnsignedInt32 xintIndex,
1142 : : UnsignedInt32& xintGeomID,
1143 : : UnsignedInt32& xintNumTypes,
1144 : : SElemData*& xpaElemData)
1145 : : // Try to read the element connectivity for the passed geometry index/ID
1146 : : // from the read-only file.
1147 : : // RETURNS: 0 on success, other values indicate error code.
1148 : : {
1149 : : UnsignedInt32 lintErrorCode;
1150 : : try {
1151 : :
1152 : 0 : CMetaData *mmd = NULL;
1153 [ # # ]: 0 : this->GetReadMetaData(CCubitFile::eModelMetaData, mmd);
1154 [ # # ]: 0 : if( !mmd )
1155 : : {
1156 : 0 : throw eFileReadError;
1157 : : }
1158 : :
1159 : : // get the data version from the file.
1160 : : // Version 1.0 has an old element type enum
1161 : 0 : double data_version = 0.0;
1162 [ # # ]: 0 : mmd->GetValue(meshModelId, "DataVersion", data_version);
1163 : :
1164 [ # # ]: 0 : if(!mpReadFEModel)
1165 : 0 : throw eOrderError;
1166 : : mpReadFEModel->ReadElems(data_version, xintIndex, xintGeomID,
1167 [ # # ]: 0 : xintNumTypes, xpaElemData);
1168 : 0 : return eSuccess;
1169 : : }
1170 : 0 : catch(EErrorCode xeErrorCode) {
1171 : 0 : lintErrorCode = xeErrorCode;
1172 : : }
1173 : 0 : catch(...) {
1174 : 0 : lintErrorCode = eUnknownError;
1175 : : }
1176 : 0 : xintNumTypes = 0;
1177 : 0 : xpaElemData = NULL;
1178 [ # # ]: 0 : return lintErrorCode;
1179 : : }
1180 : :
1181 : 0 : UnsignedInt32 CCubitFile::ReadGroupIdentity(UnsignedInt32 xintIndex,
1182 : : UnsignedInt32& xintGroupID,
1183 : : UnsignedInt32& xintGroupType,
1184 : : ConstCharPtr& xpachrGroupName)
1185 : : // Try to read the identity (ID, name, type) of the passed group index from the
1186 : : // read-only file.
1187 : : // RETURNS: 0 on success, other values indicate error code.
1188 : : {
1189 : : UnsignedInt32 lintErrorCode;
1190 : : try {
1191 [ # # ]: 0 : if(!mpReadFEModel)
1192 : 0 : throw eOrderError;
1193 : : mpReadFEModel->ReadGroupIdentity(xintIndex,
1194 [ # # ]: 0 : xintGroupID, xintGroupType, xpachrGroupName);
1195 : 0 : return eSuccess;
1196 : : }
1197 : 0 : catch(EErrorCode xeErrorCode) {
1198 : 0 : lintErrorCode = xeErrorCode;
1199 : : }
1200 : 0 : catch(...) {
1201 : 0 : lintErrorCode = eUnknownError;
1202 : : }
1203 : 0 : xintGroupID = xintGroupType = 0;
1204 : 0 : xpachrGroupName = NULL;
1205 [ # # ]: 0 : return lintErrorCode;
1206 : : }
1207 : :
1208 : 0 : UnsignedInt32 CCubitFile::ReadGroupMembers(UnsignedInt32 xintIndex,
1209 : : UnsignedInt32& xintNumTypes,
1210 : : SGroupData*& xpaGroupData)
1211 : : // Try to read the membership of the passed group index from the read-only file.
1212 : : // Note: The
1213 : : // RETURNS: 0 on success, other values indicate error code.
1214 : : {
1215 : : UnsignedInt32 lintErrorCode;
1216 : : try {
1217 [ # # ]: 0 : if(!mpReadFEModel)
1218 : 0 : throw eOrderError;
1219 [ # # ]: 0 : mpReadFEModel->ReadGroupMembers(xintIndex, xintNumTypes, xpaGroupData);
1220 : 0 : return eSuccess;
1221 : : }
1222 : 0 : catch(EErrorCode xeErrorCode) {
1223 : 0 : lintErrorCode = xeErrorCode;
1224 : : }
1225 : 0 : catch(...) {
1226 : 0 : lintErrorCode = eUnknownError;
1227 : : }
1228 : 0 : xintNumTypes = 0;
1229 : 0 : xpaGroupData = NULL;
1230 [ # # ]: 0 : return lintErrorCode;
1231 : : }
1232 : :
1233 : 0 : UnsignedInt32 CCubitFile::ReadBlock(UnsignedInt32 xintIndex,
1234 : : UnsignedInt32& xintBlockID,
1235 : : int& unique_id,
1236 : : UnsignedInt32& xintBlockType,
1237 : : UnsignedInt32& xintBlockColor,
1238 : : UnsignedInt32& xintMixedElemType,
1239 : : UnsignedInt32& xintDefPyramidType,
1240 : : UnsignedInt32& xintMaterialID,
1241 : : UnsignedInt32& xintBlockDimension,
1242 : : UnsignedInt32& xintNumTypes,
1243 : : SBlockData*& xpaBlockData,
1244 : : UnsignedInt32& xintAttributeOrder,
1245 : : double*& xpadblAttributes)
1246 : : // Try to read the membership of the passed block index from the read-only file.
1247 : : // Note: The
1248 : : // RETURNS: 0 on success, other values indicate error code.
1249 : : {
1250 : : UnsignedInt32 lintErrorCode;
1251 : : try {
1252 [ # # ]: 0 : if(!mpReadFEModel)
1253 : 0 : throw eOrderError;
1254 : : mpReadFEModel->ReadBlock(xintIndex, xintBlockID, unique_id,
1255 : : xintBlockType, xintBlockColor, xintMixedElemType,
1256 : : xintDefPyramidType, xintMaterialID, xintBlockDimension,
1257 [ # # ]: 0 : xintNumTypes, xpaBlockData, xintAttributeOrder, xpadblAttributes);
1258 : 0 : return eSuccess;
1259 : : }
1260 : 0 : catch(EErrorCode xeErrorCode) {
1261 : 0 : lintErrorCode = xeErrorCode;
1262 : : }
1263 : 0 : catch(...) {
1264 : 0 : lintErrorCode = eUnknownError;
1265 : : }
1266 : : xintBlockID = xintBlockType = xintBlockColor = xintMixedElemType =
1267 : : xintDefPyramidType = xintMaterialID = xintNumTypes =
1268 : 0 : xintAttributeOrder = 0;
1269 : 0 : xpaBlockData = NULL;
1270 : 0 : xpadblAttributes = NULL;
1271 [ # # ]: 0 : return lintErrorCode;
1272 : : }
1273 : :
1274 : 0 : UnsignedInt32 CCubitFile::ReadNodeSet(UnsignedInt32 xintIndex,
1275 : : UnsignedInt32& xintNodeSetID,
1276 : : int& unique_id,
1277 : : UnsignedInt32& xintColor,
1278 : : UnsignedInt32& xintPointSymbol,
1279 : : UnsignedInt32& xintNumTypes,
1280 : : SNodeSetData*& xpaNodeSetData,
1281 : : std::vector<char>& bcdata)
1282 : : // Try to read the membership of the passed node set index from the read-only file.
1283 : : // Note: The
1284 : : // RETURNS: 0 on success, other values indicate error code.
1285 : : {
1286 : : UnsignedInt32 lintErrorCode;
1287 : : try {
1288 [ # # ]: 0 : if(!mpReadFEModel)
1289 : 0 : throw eOrderError;
1290 : : mpReadFEModel->ReadNodeSet(xintIndex, xintNodeSetID, unique_id,
1291 [ # # ]: 0 : xintColor, xintPointSymbol, xintNumTypes, xpaNodeSetData, bcdata);
1292 : 0 : return eSuccess;
1293 : : }
1294 : 0 : catch(EErrorCode xeErrorCode) {
1295 : 0 : lintErrorCode = xeErrorCode;
1296 : : }
1297 : 0 : catch(...) {
1298 : 0 : lintErrorCode = eUnknownError;
1299 : : }
1300 : 0 : xintNodeSetID = xintColor = xintPointSymbol = xintNumTypes = 0;
1301 : 0 : xpaNodeSetData = NULL;
1302 [ # # ]: 0 : return lintErrorCode;
1303 : : }
1304 : :
1305 : 0 : UnsignedInt32 CCubitFile::ReadSideSet_10(UnsignedInt32 xintIndex,
1306 : : UnsignedInt32& xintSideSetID,
1307 : : UnsignedInt32& xintColor,
1308 : : UnsignedInt32& xintUseShells,
1309 : : UnsignedInt32& xintNumTypes,
1310 : : SSideSetData_10*& xpaSideSetData,
1311 : : UnsignedInt32& xintNumDistFact,
1312 : : double*& xpadblDistribution)
1313 : : // Try to read the membership of the passed side set index from the read-only file.
1314 : : // Note: The
1315 : : // RETURNS: 0 on success, other values indicate error code.
1316 : : {
1317 : : UnsignedInt32 lintErrorCode;
1318 : : try {
1319 [ # # ]: 0 : if(!mpReadFEModel)
1320 : 0 : throw eOrderError;
1321 : : mpReadFEModel->ReadSideSet_10(xintIndex, xintSideSetID,
1322 : : xintColor, xintUseShells, xintNumTypes, xpaSideSetData,
1323 [ # # ]: 0 : xintNumDistFact, xpadblDistribution);
1324 : 0 : return eSuccess;
1325 : : }
1326 : 0 : catch(EErrorCode xeErrorCode) {
1327 : 0 : lintErrorCode = xeErrorCode;
1328 : : }
1329 : 0 : catch(...) {
1330 : 0 : lintErrorCode = eUnknownError;
1331 : : }
1332 : 0 : xintSideSetID = xintColor = xintNumTypes = xintNumDistFact = 0;
1333 : 0 : xpaSideSetData = NULL;
1334 : 0 : xpadblDistribution = NULL;
1335 [ # # ]: 0 : return lintErrorCode;
1336 : : }
1337 : :
1338 : 0 : UnsignedInt32 CCubitFile::ReadSideSet_11(UnsignedInt32 xintIndex,
1339 : : UnsignedInt32& xintSideSetID,
1340 : : int& unique_id,
1341 : : UnsignedInt32& xintColor,
1342 : : UnsignedInt32& xintUseShells,
1343 : : UnsignedInt32& xintNumTypes,
1344 : : SSideSetData_11*& xpaSideSetData,
1345 : : UnsignedInt32& xintNumDistFact,
1346 : : double*& xpadblDistribution,
1347 : : std::vector<char>& bcdata)
1348 : : // Try to read the membership of the passed side set index from the read-only file.
1349 : : // Note: The
1350 : : // RETURNS: 0 on success, other values indicate error code.
1351 : : {
1352 : : UnsignedInt32 lintErrorCode;
1353 : : try {
1354 [ # # ]: 0 : if(!mpReadFEModel)
1355 : 0 : throw eOrderError;
1356 : : mpReadFEModel->ReadSideSet_11(xintIndex, xintSideSetID, unique_id,
1357 : : xintColor, xintUseShells, xintNumTypes, xpaSideSetData,
1358 [ # # ]: 0 : xintNumDistFact, xpadblDistribution, bcdata);
1359 : 0 : return eSuccess;
1360 : : }
1361 : 0 : catch(EErrorCode xeErrorCode) {
1362 : 0 : lintErrorCode = xeErrorCode;
1363 : : }
1364 : 0 : catch(...) {
1365 : 0 : lintErrorCode = eUnknownError;
1366 : : }
1367 : 0 : xintSideSetID = xintColor = xintNumTypes = xintNumDistFact = 0;
1368 : 0 : xpaSideSetData = NULL;
1369 : 0 : xpadblDistribution = NULL;
1370 [ # # ]: 0 : return lintErrorCode;
1371 : : }
1372 : :
1373 : 0 : UnsignedInt32 CCubitFile::EndReadFEModel()
1374 : : // Designate the end of reading a FEA model and free any memory allocated for
1375 : : // the read operations.
1376 : : // RETURNS: 0 on success, other values indicate error code.
1377 : : {
1378 : : try {
1379 [ # # ]: 0 : if(!mpReadFEModel)
1380 : 0 : return eOrderError;
1381 [ # # ]: 0 : mpReadFEModel->EndRead();
1382 [ # # ][ # # ]: 0 : delete mpReadFEModel;
1383 : 0 : mpReadFEModel = NULL;
1384 [ # # ]: 0 : return eSuccess;
1385 : : }
1386 : 0 : catch(EErrorCode xeErrorCode) { return xeErrorCode; }
1387 : 0 : catch(...) { return eUnknownError; }
1388 : : }
1389 : :
1390 : 0 : UnsignedInt32 CCubitFile::BeginWriteSimModel(HModel xintSimModel,
1391 : : UnsignedInt32 xintBCCount,
1392 : : UnsignedInt32 xintICCount,
1393 : : UnsignedInt32 xintBCSetCount,
1394 : : UnsignedInt32 xintMaterialCount,
1395 : : UnsignedInt32 xintAmplitudeCount,
1396 : : UnsignedInt32 xintConstraintCount)
1397 : : {
1398 : : try {
1399 [ # # ][ # # ]: 0 : if(!mpWriteFile) throw eFileWriteError;
1400 [ # # ]: 0 : if(mpWriteSimModel) throw eOrderError;
1401 : :
1402 : : // Write the model table first to try to guarentee that it will be
1403 : : // at the beginning of the file.
1404 [ # # ]: 0 : WriteModelTable();
1405 : :
1406 : : // Lookup the requested model in the model table and make sure it is
1407 : : // an FEA model.
1408 [ # # ]: 0 : if(!FindModel(xintSimModel, mpaWriteModels, mWriteContents.mintNumModels,
1409 [ # # ]: 0 : mintSimModelIndex))
1410 : 0 : throw eNotFound;
1411 [ # # ]: 0 : if(mpaWriteModels[mintSimModelIndex].mintModelType != eSimModel)
1412 : 0 : throw eNotFound;
1413 : :
1414 : : // Create the object that manages FEA model file transactions and have
1415 : : // it begin its model write.
1416 [ # # ]: 0 : mpWriteSimModel = new CSimModel();
[ # # # # ]
1417 [ # # ]: 0 : if(!mpWriteSimModel)
1418 : 0 : throw eMemoryError;
1419 : :
1420 : 0 : mpaWriteModels[mintSimModelIndex].mintModelOffset =
1421 : : mpWriteSimModel->InitWrite(mpWriteFile.file(), xintBCCount,
1422 : : xintICCount, xintBCSetCount,
1423 : : xintMaterialCount, xintAmplitudeCount,
1424 [ # # ][ # # ]: 0 : xintConstraintCount);
1425 : 0 : return eSuccess;
1426 : : }
1427 : 0 : catch(EErrorCode xeErrorCode) { return xeErrorCode; }
1428 : 0 : catch(...) { return eUnknownError; }
1429 : : }
1430 : :
1431 : 0 : UnsignedInt32 CCubitFile::WriteBCSet(UnsignedInt32 xintIndex,
1432 : : UnsignedInt32 xintBCSetID,
1433 : : UnsignedInt32 xintBCSetUniqueID,
1434 : : UnsignedInt32 xintBCSetAnalysisType,
1435 : : UnsignedInt32 xintRestraintTypesCount,
1436 : : UnsignedInt32 xintLoadTypesCount,
1437 : : UnsignedInt32 xintContactPairTypesCount,
1438 : : SBCSetData* xpaBCSetRestraintData,
1439 : : SBCSetData* xpaBCSetLoadData,
1440 : : SBCSetData* xpaBCSetContactPairData)
1441 : : // Try to write the membership of the passed group index to the writable file.
1442 : : // RETURNS: 0 on success, other values indicate error code.
1443 : : {
1444 : : try {
1445 [ # # ]: 0 : if(!mpWriteSimModel)
1446 : 0 : throw eOrderError;
1447 : :
1448 : : mpWriteSimModel->WriteBCSet(xintIndex,xintBCSetID,xintBCSetUniqueID,
1449 : : xintBCSetAnalysisType,xintRestraintTypesCount,xintLoadTypesCount,
1450 : : xintContactPairTypesCount,xpaBCSetRestraintData,
1451 [ # # ]: 0 : xpaBCSetLoadData,xpaBCSetContactPairData);
1452 : :
1453 [ # # ]: 0 : return eSuccess;
1454 : : }
1455 : 0 : catch(EErrorCode xeErrorCode) { return xeErrorCode; }
1456 : 0 : catch(...) { return eUnknownError; }
1457 : : }
1458 : :
1459 : 0 : UnsignedInt32 CCubitFile::WriteMaterial(UnsignedInt32 xintIndex,
1460 : : UnsignedInt32 xintMaterialID,
1461 : : UnsignedInt32 xintMaterialUniqueID,
1462 : : UnsignedInt32 xintPropertiesCount,
1463 : : SMaterialData* xpaMaterialData
1464 : : )
1465 : : {
1466 : : try {
1467 [ # # ]: 0 : if(!mpWriteSimModel)
1468 : 0 : throw eOrderError;
1469 : :
1470 : : mpWriteSimModel->WriteMaterial(xintIndex,xintMaterialID,xintMaterialUniqueID,
1471 [ # # ]: 0 : xintPropertiesCount,xpaMaterialData);
1472 : :
1473 [ # # ]: 0 : return eSuccess;
1474 : : }
1475 : 0 : catch(EErrorCode xeErrorCode) { return xeErrorCode; }
1476 : 0 : catch(...) { return eUnknownError; }
1477 : : }
1478 : :
1479 : 0 : UnsignedInt32 CCubitFile::WriteConstraint(UnsignedInt32 xintIndex,
1480 : : UnsignedInt32 xintConstraintID,
1481 : : UnsignedInt32 xintConstraintUniqueID,
1482 : : UnsignedInt32 xintConstraintType,
1483 : : UnsignedInt32 xintIndependentTypeCount,
1484 : : SConstraintData* xpaIndependentData,
1485 : : UnsignedInt32 xintDependentTypeCount,
1486 : : SConstraintData* xpaDependentData
1487 : : )
1488 : : {
1489 : : try {
1490 [ # # ]: 0 : if(!mpWriteSimModel)
1491 : 0 : throw eOrderError;
1492 : :
1493 : : mpWriteSimModel->WriteConstraint(xintIndex,xintConstraintID,xintConstraintUniqueID,
1494 : : xintConstraintType,xintIndependentTypeCount,xpaIndependentData,
1495 [ # # ]: 0 : xintDependentTypeCount,xpaDependentData);
1496 : :
1497 [ # # ]: 0 : return eSuccess;
1498 : : }
1499 : 0 : catch(EErrorCode xeErrorCode) { return xeErrorCode; }
1500 : 0 : catch(...) { return eUnknownError; }
1501 : : }
1502 : :
1503 : 0 : UnsignedInt32 CCubitFile::EndWriteSimModel()
1504 : : {
1505 : : try {
1506 [ # # ]: 0 : if(!mpWriteSimModel)
1507 : 0 : throw eOrderError;
1508 : 0 : mpaWriteModels[mintSimModelIndex].mintModelLength =
1509 [ # # ]: 0 : mpWriteSimModel->EndWrite();
1510 [ # # ][ # # ]: 0 : delete mpWriteSimModel;
1511 : 0 : mpWriteSimModel = NULL;
1512 : :
1513 : : UnsignedInt32 lintReadIndex;
1514 [ # # ]: 0 : if(FindModel(mpaWriteModels[mintSimModelIndex].mintModelHandle,
1515 [ # # ]: 0 : mpaReadModels, mReadContents.mintNumModels, lintReadIndex))
1516 : 0 : mpaReadModelStat[lintReadIndex] = eStatWritten;
1517 : :
1518 [ # # ]: 0 : return eSuccess;
1519 : : }
1520 : 0 : catch(EErrorCode xeErrorCode) { return xeErrorCode; }
1521 : 0 : catch(...) { return eUnknownError; }
1522 : : }
1523 : :
1524 : 0 : UnsignedInt32 CCubitFile::BeginReadSimModel(HModel xintSimModel,
1525 : : UnsignedInt32& xintBCCount,
1526 : : UnsignedInt32& xintICCount,
1527 : : UnsignedInt32& xintBCSetCount,
1528 : : UnsignedInt32& xintMaterialCount,
1529 : : UnsignedInt32& xintAmplitudeCount,
1530 : : UnsignedInt32& xintConstraintCount)
1531 : : {
1532 : : try {
1533 [ # # ][ # # ]: 0 : if(!mpReadFile) throw eFileReadError;
1534 [ # # ]: 0 : if(mpReadSimModel) throw eOrderError;
1535 : :
1536 : : UnsignedInt32 lintIndex;
1537 [ # # ]: 0 : if(!FindModel(xintSimModel, mpaReadModels, mReadContents.mintNumModels,
1538 [ # # ]: 0 : lintIndex))
1539 : 0 : throw eNotFound;
1540 [ # # ]: 0 : if(mpaReadModels[lintIndex].mintModelType != eSimModel)
1541 : 0 : throw eNotFound;
1542 : :
1543 [ # # ]: 0 : mpReadSimModel = new CSimModel();
[ # # # # ]
1544 [ # # ]: 0 : if(!mpReadSimModel) throw eMemoryError;
1545 : :
1546 : 0 : mpReadSimModel->InitRead(mpReadFile.file(), mpaReadModels[lintIndex].mintModelOffset,
1547 : : xintBCCount, xintICCount, xintBCSetCount,
1548 : : xintMaterialCount, xintAmplitudeCount,
1549 [ # # ][ # # ]: 0 : xintConstraintCount);
1550 : 0 : return eSuccess;
1551 : : }
1552 : 0 : catch(EErrorCode xeErrorCode) { return xeErrorCode; }
1553 : 0 : catch(...) { return eUnknownError; }
1554 : : }
1555 : :
1556 : 0 : UnsignedInt32 CCubitFile::ReadBCSet(UnsignedInt32 xintIndex,
1557 : : UnsignedInt32& xintBCSetID,
1558 : : UnsignedInt32& xintBCSetUniqueID,
1559 : : UnsignedInt32& xintBCSetAnalysisType,
1560 : : UnsignedInt32& xintRestraintTypesCount,
1561 : : UnsignedInt32& xintLoadTypesCount,
1562 : : UnsignedInt32& xintContactPairTypesCount,
1563 : : SBCSetData*& xpaBCSetRestraintData,
1564 : : SBCSetData*& xpaBCSetLoadData,
1565 : : SBCSetData*& xpaBCSetContactPairData)
1566 : : // Try to read the membership of the passed node set index from the read-only file.
1567 : : // Note: The
1568 : : // RETURNS: 0 on success, other values indicate error code.
1569 : : {
1570 : : UnsignedInt32 lintErrorCode;
1571 : : try {
1572 [ # # ]: 0 : if(!mpReadSimModel)
1573 : 0 : throw eOrderError;
1574 : :
1575 : : mpReadSimModel->ReadBCSet(xintIndex,xintBCSetID,xintBCSetUniqueID,
1576 : : xintBCSetAnalysisType,xintRestraintTypesCount,
1577 : : xintLoadTypesCount,xintContactPairTypesCount,xpaBCSetRestraintData,
1578 [ # # ]: 0 : xpaBCSetLoadData,xpaBCSetContactPairData);
1579 : :
1580 : 0 : return eSuccess;
1581 : : }
1582 : 0 : catch(EErrorCode xeErrorCode) {
1583 : 0 : lintErrorCode = xeErrorCode;
1584 : : }
1585 : 0 : catch(...) {
1586 : 0 : lintErrorCode = eUnknownError;
1587 : : }
1588 : 0 : xintBCSetID = xintBCSetUniqueID = xintBCSetAnalysisType = 0;
1589 : 0 : xintRestraintTypesCount = xintLoadTypesCount = xintContactPairTypesCount = 0;
1590 : 0 : xpaBCSetRestraintData = NULL;
1591 : 0 : xpaBCSetLoadData = NULL;
1592 : 0 : xpaBCSetContactPairData = NULL;
1593 [ # # ]: 0 : return lintErrorCode;
1594 : : }
1595 : :
1596 : 0 : UnsignedInt32 CCubitFile::ReadMaterial(UnsignedInt32 xintIndex,
1597 : : UnsignedInt32& xintMaterialID,
1598 : : UnsignedInt32& xintMaterialUniqueID,
1599 : : UnsignedInt32& xintPropertiesCount,
1600 : : SMaterialData*& xpaMaterialData
1601 : : )
1602 : : {
1603 : : UnsignedInt32 lintErrorCode;
1604 : : try {
1605 [ # # ]: 0 : if(!mpReadSimModel)
1606 : 0 : throw eOrderError;
1607 : :
1608 : : mpReadSimModel->ReadMaterial(xintIndex,xintMaterialID,xintMaterialUniqueID,
1609 [ # # ]: 0 : xintPropertiesCount,xpaMaterialData);
1610 : :
1611 : 0 : return eSuccess;
1612 : : }
1613 : 0 : catch(EErrorCode xeErrorCode) {
1614 : 0 : lintErrorCode = xeErrorCode;
1615 : : }
1616 : 0 : catch(...) {
1617 : 0 : lintErrorCode = eUnknownError;
1618 : : }
1619 : 0 : xintMaterialID = xintMaterialUniqueID = xintPropertiesCount = 0;
1620 : 0 : xpaMaterialData = NULL;
1621 [ # # ]: 0 : return lintErrorCode;
1622 : : }
1623 : :
1624 : 0 : UnsignedInt32 CCubitFile::ReadConstraint(UnsignedInt32 xintIndex,
1625 : : UnsignedInt32& xintConstraintID,
1626 : : UnsignedInt32& xintConstraintUniqueID,
1627 : : UnsignedInt32& xintConstraintType,
1628 : : UnsignedInt32& xintIndependentTypeCount,
1629 : : SConstraintData*& xpaIndependentData,
1630 : : UnsignedInt32& xintDependentTypeCount,
1631 : : SConstraintData*& xpaDependentData
1632 : : )
1633 : : {
1634 : : UnsignedInt32 lintErrorCode;
1635 : : try {
1636 [ # # ]: 0 : if(!mpReadSimModel)
1637 : 0 : throw eOrderError;
1638 : :
1639 : : mpReadSimModel->ReadConstraint(xintIndex,xintConstraintID,xintConstraintUniqueID,
1640 : : xintConstraintType,xintIndependentTypeCount,xpaIndependentData,
1641 [ # # ]: 0 : xintDependentTypeCount,xpaDependentData);
1642 : :
1643 : 0 : return eSuccess;
1644 : : }
1645 : 0 : catch(EErrorCode xeErrorCode) {
1646 : 0 : lintErrorCode = xeErrorCode;
1647 : : }
1648 : 0 : catch(...) {
1649 : 0 : lintErrorCode = eUnknownError;
1650 : : }
1651 : 0 : xintConstraintID = xintConstraintUniqueID = xintConstraintType = 0;
1652 : 0 : xpaIndependentData = xpaDependentData = NULL;
1653 [ # # ]: 0 : return lintErrorCode;
1654 : : }
1655 : :
1656 : 0 : UnsignedInt32 CCubitFile::EndReadSimModel()
1657 : : {
1658 : : try {
1659 [ # # ]: 0 : if(!mpReadSimModel)
1660 : 0 : return eOrderError;
1661 [ # # ]: 0 : mpReadSimModel->EndRead();
1662 [ # # ][ # # ]: 0 : delete mpReadSimModel;
1663 : 0 : mpReadSimModel = NULL;
1664 [ # # ]: 0 : return eSuccess;
1665 : : }
1666 : 0 : catch(EErrorCode xeErrorCode) { return xeErrorCode; }
1667 : 0 : catch(...) { return eUnknownError; }
1668 : : }
1669 : :
1670 : : ///////////////////////////////////////////////////////////////////////////////
1671 : : // Meta-data accessors
1672 : : ///////////////////////////////////////////////////////////////////////////////
1673 : :
1674 : 0 : UnsignedInt32 CCubitFile::GetReadMetaData(EMetaDataOwnerType xeType,
1675 : : CMetaData*& xpMetaData)
1676 : : // Return the requested meta-data object for the read file if possible.
1677 : : {
1678 : 0 : xpMetaData = NULL;
1679 [ # # ]: 0 : if(xeType == eModelMetaData)
1680 : 0 : xpMetaData = mpMetaData;
1681 [ # # ]: 0 : else if(mpReadFEModel) {
1682 [ # # # # : 0 : switch(xeType) {
# # # # ]
1683 : : case eGeomMetaData:
1684 : 0 : xpMetaData = &mpReadFEModel->GetGeomMetaData();
1685 : 0 : break;
1686 : : case eNodeMetaData:
1687 : 0 : xpMetaData = &mpReadFEModel->GetNodeMetaData();
1688 : 0 : break;
1689 : : case eElemMetaData:
1690 : 0 : xpMetaData = &mpReadFEModel->GetElemMetaData();
1691 : 0 : break;
1692 : : case eGroupMetaData:
1693 : 0 : xpMetaData = &mpReadFEModel->GetGroupMetaData();
1694 : 0 : break;
1695 : : case eBlockMetaData:
1696 : 0 : xpMetaData = &mpReadFEModel->GetBlockMetaData();
1697 : 0 : break;
1698 : : case eNodeSetMetaData:
1699 : 0 : xpMetaData = &mpReadFEModel->GetNodeSetMetaData();
1700 : 0 : break;
1701 : : case eSideSetMetaData:
1702 : 0 : xpMetaData = &mpReadFEModel->GetSideSetMetaData();
1703 : 0 : break;
1704 : : default:
1705 : 0 : break;
1706 : : }
1707 : : }
1708 [ # # ]: 0 : else if (mpReadSimModel) {
1709 [ # # # # ]: 0 : switch (xeType) {
1710 : : case eBCSetMetaData:
1711 : 0 : xpMetaData = &mpReadSimModel->GetBCSetMetaData();
1712 : 0 : break;
1713 : : case eMaterialMetaData:
1714 : 0 : xpMetaData = &mpReadSimModel->GetMaterialMetaData();
1715 : 0 : break;
1716 : : case eConstraintMetaData:
1717 : 0 : xpMetaData = &mpReadSimModel->GetConstraintMetaData();
1718 : 0 : break;
1719 : : default:
1720 : 0 : break;
1721 : : }
1722 : : }
1723 : : else
1724 : 0 : return eOrderError;
1725 [ # # ]: 0 : return xpMetaData ? eSuccess : eNotFound;
1726 : : }
1727 : :
1728 : 0 : UnsignedInt32 CCubitFile::GetWriteMetaData(EMetaDataOwnerType xeType,
1729 : : CMetaData*& xpMetaData)
1730 : : // Return the requested meta-data object for the write file if possible.
1731 : : {
1732 : 0 : xpMetaData = NULL;
1733 [ # # ]: 0 : if(xeType == eModelMetaData)
1734 : 0 : xpMetaData = mpMetaData;
1735 [ # # ]: 0 : else if(mpWriteFEModel) {
1736 [ # # # # : 0 : switch(xeType) {
# # # # ]
1737 : : case eGeomMetaData:
1738 : 0 : xpMetaData = &mpWriteFEModel->GetGeomMetaData();
1739 : 0 : break;
1740 : : case eNodeMetaData:
1741 : 0 : xpMetaData = &mpWriteFEModel->GetNodeMetaData();
1742 : 0 : break;
1743 : : case eElemMetaData:
1744 : 0 : xpMetaData = &mpWriteFEModel->GetElemMetaData();
1745 : 0 : break;
1746 : : case eGroupMetaData:
1747 : 0 : xpMetaData = &mpWriteFEModel->GetGroupMetaData();
1748 : 0 : break;
1749 : : case eBlockMetaData:
1750 : 0 : xpMetaData = &mpWriteFEModel->GetBlockMetaData();
1751 : 0 : break;
1752 : : case eNodeSetMetaData:
1753 : 0 : xpMetaData = &mpWriteFEModel->GetNodeSetMetaData();
1754 : 0 : break;
1755 : : case eSideSetMetaData:
1756 : 0 : xpMetaData = &mpWriteFEModel->GetSideSetMetaData();
1757 : 0 : break;
1758 : : default:
1759 : 0 : break;
1760 : : }
1761 : : }
1762 [ # # ]: 0 : else if (mpWriteSimModel) {
1763 [ # # # # ]: 0 : switch (xeType) {
1764 : : case eBCSetMetaData:
1765 : 0 : xpMetaData = &mpWriteSimModel->GetBCSetMetaData();
1766 : 0 : break;
1767 : : case eMaterialMetaData:
1768 : 0 : xpMetaData = &mpWriteSimModel->GetMaterialMetaData();
1769 : 0 : break;
1770 : : case eConstraintMetaData:
1771 : 0 : xpMetaData = &mpWriteSimModel->GetConstraintMetaData();
1772 : 0 : break;
1773 : : default:
1774 : 0 : break;
1775 : : }
1776 : : }
1777 : : else
1778 : 0 : return eOrderError;
1779 [ # # ]: 0 : return xpMetaData ? eSuccess : eNotFound;
1780 : : }
|