cgma
CCubitFile.hpp
Go to the documentation of this file.
00001 /*******************************************************************************
00002     COPYRIGHT 2002 CATERPILLAR INC.  ALL RIGHTS RESERVED
00003 
00004     This program is the property of Caterpillar Inc., includes Caterpillar's
00005     confidential and trade secret information, and is maintained as an
00006     unpublished copyrighted work.  It is not to be copied or used by others
00007     except under license from Caterpillar.  This program is also protected as an
00008     unpublished work in accordance with the copyright act of 1976.  In the event
00009     of either inadvertent or deliberate publication, Caterpillar Inc. intends to
00010     maintain copyright protection for this work under the relevant copyright
00011     laws pertaining to published works.  The inclusion of a copyright notice
00012     hereon is precautionary only, and does not imply publication or disclosure.
00013 
00014  
00015  Filename      : CCubitFile.hpp
00016 
00017  Purpose       : Declares an interface for reading and writing data in the
00018                  Cubit (*.cub) file format.
00019            
00020  Special Notes :
00021 
00022  Creator       : Will A. Helden
00023 
00024  Creation Date : 02/15/02
00025 
00026  Owner         : Will A. Helden
00027 
00028 *******************************************************************************/
00029 
00030 #ifndef CCubitFile_HPP
00031 #define CCubitFile_HPP
00032 
00033 #include <stdio.h>
00034 #include <cstdio>
00035 #include <memory.h>
00036 #include "CGMUtilConfigure.h"
00037 #include <vector>
00038 #include "CubitFile.hpp"
00039 
00040 namespace NCubitFile {
00041 
00042 class CMetaData;
00043 class CFEModel;
00044 class CSimModel;
00045 
00046 typedef unsigned int UnsignedInt32;  // This must always be a 32 bit integer!!!
00047 typedef const char* ConstCharPtr;
00048 
00049 struct SModelData {
00050     UnsignedInt32 mintModelHandle;
00051     UnsignedInt32 mintModelType;
00052     UnsignedInt32 mintModelOwner;
00053 };
00054 struct SElemData {
00055     UnsignedInt32 mintElemType;
00056     UnsignedInt32 mintElemOrder;
00057     UnsignedInt32 mintElemCount;
00058     UnsignedInt32* mpaElemIDs;
00059     UnsignedInt32* mpaElemGlobalIDs;
00060     UnsignedInt32* mpaElemConnect;
00061 };
00062 struct SGroupData {
00063     UnsignedInt32 mintMemberType;
00064     UnsignedInt32 mintMemberCount;
00065     UnsignedInt32* mpaMemberIDs;
00066 };
00067 typedef SGroupData SBlockData;
00068 typedef SGroupData SNodeSetData;
00069 typedef SGroupData SBCSetData;
00070 typedef SGroupData SConstraintData;
00071 
00072 // first edition of sideset data
00073 struct SSideSetData_10 {
00074     UnsignedInt32 mintMemberType;
00075     UnsignedInt32 mintMemberCount;
00076     UnsignedInt32 mintMemberSenseSize;
00077     UnsignedInt32* mpaintMemberIDs;
00078     char* mpachrMemberSense;
00079     UnsignedInt32* mpaintMemberSense;
00080     char* mpachrMemberSideNumber;
00081 };
00082 // next edition of sideset data holds more information in a more flexible way
00083 struct SSideSetData_11 {
00084     UnsignedInt32 mintMemberCount;  // number of members {type,id} ...
00085     UnsignedInt32* mpaintMemberTypes; // types of each member
00086     UnsignedInt32* mpaintMemberIDs; // ids of the members
00087     char* mpachrMemberSenses;        // shell sense (forward, reverse, both)
00088     UnsignedInt32* mpaintMemberWRTEntities; // wrt entities, format is  ( {num_wrt} {type,id} {type,id} ...
00089                                             //                            {num_wrt} {type,id} ...
00090 };
00091 
00092 struct SMaterialData {
00093     UnsignedInt32 mintMemberType;
00094     UnsignedInt32 mintMemberRows; //i.e. rows
00095     UnsignedInt32 mintMemberColumns;
00096     double* mpadblMemberData;
00097 };
00098 
00099 class CUBIT_UTIL_EXPORT CCubitFile  
00100 {
00101 public:
00102     typedef UnsignedInt32 HModel;
00103     enum EErrorCode { eSuccess = 0,
00104         eFileReadError, eFileSeekError, eFileTellError, eFileWriteError,
00105         eFileUnrecognizedFormat,
00106         eDuplicateWrite, eCorruptBlock,
00107         eNotFound, eOrderError,
00108         eMemoryError, ePassedNullPointer,
00109         eUnknownError
00110     };
00111     enum EMetaDataOwnerType {
00112         eModelMetaData,
00113         eGeomMetaData, eNodeMetaData, eElemMetaData, eGroupMetaData,
00114         eBlockMetaData, eNodeSetMetaData, eSideSetMetaData,
00115         eBCSetMetaData, eMaterialMetaData, eConstraintMetaData
00116     };
00117     enum EModelType {
00118       eFEModel, eACISText, eACISBinary, eAssemblyModel, eSimModel, eBoundaryLayerModel
00119     };
00120     enum ESideSetSenseSize {
00121         eSideSetSenseNone, eSideSetSenseByte, eSideSetSenseInt32
00122     };
00123     enum EConstraintType {
00124         eConstraintDistributing, eConstraintKinematic, eConstraintRigidBody
00125     };
00126 
00127     CCubitFile();
00128     virtual ~CCubitFile();
00129 
00130     EErrorCode Open(const char* xstrReadFileName, const char* xstrWriteFileName,
00131         const char* xstrBackupFileName = NULL);
00132     EErrorCode Close();
00133 
00134     UnsignedInt32 GetModelList(UnsignedInt32& xintNumModels,
00135         const SModelData*& xpaModels);
00136     UnsignedInt32 IsModel(HModel xintModel);
00137     UnsignedInt32 GetReadModelLength(HModel xintModel,
00138                                      UnsignedInt32& xintLength);
00139     UnsignedInt32 CreateModel(EModelType xeModelType, HModel& xintModel);
00140     UnsignedInt32 DeleteModel(HModel xintModel);
00141     UnsignedInt32 GetModelOwner(HModel xintModel, HModel& xintOwner);
00142     UnsignedInt32 SetModelOwner(HModel xintModel, HModel xintOwner);
00143 
00144     // Returns a FILE* that can be directly written to.  Be sure to
00145     // call EndWriteAssemblyModel() to correctly accomodate the written data.
00146   UnsignedInt32 BeginWriteModel(HModel xintModelId, EModelType type,
00147                                         FILE*& writeable_file);
00148   UnsignedInt32 EndWriteModel(HModel xintModelId);
00149     // Returns a FILE* that can be read from.  The FILE* will NOT return EOF
00150     // at the end of the data...the reader should not go GetReadModelLength()
00151     // bytes beyond the current FILE* position.  You should copy the contents
00152     // to another FILE if this is an issue for the reader.
00153   UnsignedInt32 BeginReadModel(HModel xintGeomModel, EModelType type,
00154                                        FILE*& readable_file);
00155   UnsignedInt32 EndReadModel();
00156   
00157   UnsignedInt32 BeginWriteGeomModel(HModel xintGeomModel,
00158                                     const char* xstrGeomFile);
00159   UnsignedInt32 EndWriteGeomModel();
00160   UnsignedInt32 BeginReadGeomModel(HModel xintGeomModel,
00161                                    FILE* xpGeomFile);
00162   UnsignedInt32 EndReadGeomModel();
00163   
00164   UnsignedInt32 BeginWriteFEModel(HModel xintFEModel,
00165                                   UnsignedInt32 xintGeomCount,
00166                                   UnsignedInt32 xintGroupCount,
00167                                   UnsignedInt32 xintBlockCount,
00168                                   UnsignedInt32 xintNodeSetCount,
00169                                   UnsignedInt32 xintSideSetCount);
00170   UnsignedInt32 WriteNodes(UnsignedInt32 xintIndex, UnsignedInt32 xintGeomID,
00171                            UnsignedInt32 xintNodeCount, UnsignedInt32 *xpaintNodeIDs,
00172                            double *xpadblX, double *xpadblY, double *xpadblZ);
00173   UnsignedInt32 WriteElems(UnsignedInt32 xintIndex,
00174                            UnsignedInt32 xintNumTypes, SElemData* xpaElemData);
00175   UnsignedInt32 WriteGroup(UnsignedInt32 xintIndex,
00176                            UnsignedInt32 xintGroupID, UnsignedInt32 xintGroupType,
00177                            ConstCharPtr xpachrGroupName,
00178                            UnsignedInt32 xintNumTypes, SGroupData* xpaGroupData);
00179   UnsignedInt32 WriteBlock(UnsignedInt32 xintIndex,
00180                            UnsignedInt32 xintBlockID, 
00181                            int block_unique_id, 
00182                            UnsignedInt32 xintBlockType,
00183                            UnsignedInt32 xintBlockColor, UnsignedInt32 xintMixedElemType,
00184                            UnsignedInt32 xintDefPyramidType, UnsignedInt32 xintMaterialID,
00185                            UnsignedInt32 xintBlockDimension,
00186                            UnsignedInt32 xintNumTypes, SBlockData* xpaBlockData,
00187                            UnsignedInt32 xintAttributeOrder, double* xpadblAttributes);
00188   UnsignedInt32 WriteNodeSet(UnsignedInt32 xintIndex,
00189                              UnsignedInt32 xintNodeSetID, 
00190                              int nodeset_unique_id, 
00191                              UnsignedInt32 xintColor,
00192                              UnsignedInt32 xintPointSymbol,
00193                              UnsignedInt32 xintNumTypes, SNodeSetData* xpaNodeSetData,
00194                              const std::vector<char>& bcdata
00195                              );
00196   UnsignedInt32 WriteSideSet_11(UnsignedInt32 xintIndex,
00197                              UnsignedInt32 xintSideSetID,
00198                              int sideset_unique_id, 
00199                              UnsignedInt32 xintColor,
00200                              UnsignedInt32 xintUseShells,
00201                              UnsignedInt32 xintNumTypes, SSideSetData_11* xpaSideSetData,
00202                              UnsignedInt32 xintNumDistFact, double* xpadblDistribution,
00203                              const std::vector<char>& bcdata);
00204   UnsignedInt32 EndWriteFEModel();
00205   
00206   UnsignedInt32 BeginReadFEModel(HModel xintFEModel,
00207                                  UnsignedInt32& xintGeomCount,
00208                                  UnsignedInt32& xintGroupCount,
00209                                  UnsignedInt32& xintBlockCount,
00210                                  UnsignedInt32& xintNodeSetCount,
00211                                  UnsignedInt32& xintSideSetCount);
00212   UnsignedInt32 ReadNodes(UnsignedInt32 xintIndex, UnsignedInt32& xintGeomID,
00213                           UnsignedInt32& xintNodeCount, UnsignedInt32*& xpaintNodeIDs,
00214                           double*& xpadblX, double*& xpadblY, double*& xpadblZ);
00215   UnsignedInt32 ReadElems(HModel xintFEModel, UnsignedInt32 xintIndex, UnsignedInt32& xintGeomID,
00216                           UnsignedInt32& xintNumTypes, SElemData*& xpaElemData);
00217   UnsignedInt32 ReadGroupIdentity(UnsignedInt32 xintIndex,
00218                                   UnsignedInt32& xintGroupID,
00219                                   UnsignedInt32& xintGroupType,
00220                                   ConstCharPtr& xpachrGroupName);
00221   UnsignedInt32 ReadGroupMembers(UnsignedInt32 xintIndex,
00222                                  UnsignedInt32& xintNumTypes, SGroupData*& xpaGroupData);
00223     UnsignedInt32 ReadBlock(UnsignedInt32 xintIndex,
00224         UnsignedInt32& xintBlockID, int& unique_id, UnsignedInt32& xintBlockType,
00225         UnsignedInt32& xintBlockColor, UnsignedInt32& xintMixedElemType,
00226         UnsignedInt32& xintDefPyramidType, UnsignedInt32& xintMaterialID,
00227         UnsignedInt32& xintBlockDimension,
00228         UnsignedInt32& xintNumTypes, SBlockData*& xpaBlockData,
00229         UnsignedInt32& xintAttributeOrder, double*& xpadblAttributes);
00230     UnsignedInt32 ReadNodeSet(UnsignedInt32 xintIndex,
00231         UnsignedInt32& xintNodeSetID, int& unique_id, UnsignedInt32& xintColor,
00232         UnsignedInt32& xintPointSymbol,
00233         UnsignedInt32& xintNumTypes, SNodeSetData*& xpaNodeSetData,
00234         std::vector<char>& bcdata);
00235 
00236     // read old sideset format
00237     UnsignedInt32 ReadSideSet_10(UnsignedInt32 xintIndex,
00238         UnsignedInt32& xintSideSetID, UnsignedInt32& xintColor,
00239         UnsignedInt32& xintUseShells,
00240         UnsignedInt32& xintNumTypes, SSideSetData_10*& xpaSideSetData,
00241         UnsignedInt32& xintNumDistFact, double*& xpadblDistribution);
00242     
00243     // read new sideset format
00244     UnsignedInt32 ReadSideSet_11(UnsignedInt32 xintIndex,
00245         UnsignedInt32& xintSideSetID, int& unique_id, UnsignedInt32& xintColor,
00246         UnsignedInt32& xintUseShells,
00247         UnsignedInt32& xintNumTypes, SSideSetData_11*& xpaSideSetData,
00248         UnsignedInt32& xintNumDistFact, double*& xpadblDistribution,
00249         std::vector<char>& bcdata);
00250     
00251     UnsignedInt32 EndReadFEModel();
00252 
00253     // Simulation Model functions
00254     UnsignedInt32 BeginWriteSimModel(HModel xintGeomModel,
00255                                      UnsignedInt32 xintBCCount,
00256                                      UnsignedInt32 xintICCount,
00257                                      UnsignedInt32 xintBCSetCount,
00258                                      UnsignedInt32 xintMaterialCount,
00259                                      UnsignedInt32 xintAmplitudeCount,
00260                                      UnsignedInt32 xintConstraintCount
00261                                      );
00262     UnsignedInt32 WriteBCSet(UnsignedInt32 xintIndex,
00263                              UnsignedInt32 xintBCSetID,
00264                              UnsignedInt32 xintBCSetUniqueID,
00265                              UnsignedInt32 xintBCSetAnalysisType,
00266                              UnsignedInt32 xintRestraintTypesCount,
00267                              UnsignedInt32 xintLoadTypesCount,
00268                              UnsignedInt32 xintContactPairTypesCount,
00269                              SBCSetData* xpaBCSetRestraintData,
00270                              SBCSetData* xpaBCSetLoadData,
00271                              SBCSetData* xpaBCSetContactPairData
00272                              );
00273     UnsignedInt32 WriteMaterial(UnsignedInt32 xintIndex,
00274                                 UnsignedInt32 xintMaterialID,
00275                                 UnsignedInt32 xintMaterialUniqueID,
00276                                 UnsignedInt32 xintPropertiesCount,
00277                                 SMaterialData* xpaMaterialData
00278                                 );
00279     UnsignedInt32 WriteConstraint(UnsignedInt32 xintIndex,
00280                                 UnsignedInt32 xintConstraintID,
00281                                 UnsignedInt32 xintConstraintUniqueID,
00282                                 UnsignedInt32 xintConstraintType,
00283                                 UnsignedInt32 xintIndependentTypeCount,
00284                                 SConstraintData* xpaIndependentData,
00285                                 UnsignedInt32 xintDependentTypeCount,
00286                                 SConstraintData* xpaDependentData
00287                                 );
00288     UnsignedInt32 EndWriteSimModel();
00289 
00290     UnsignedInt32 BeginReadSimModel(HModel xintGeomModel,
00291                                     UnsignedInt32& xintBCCount,
00292                                     UnsignedInt32& xintICCount,
00293                                     UnsignedInt32& xintBCSetCount,
00294                                     UnsignedInt32& xintMaterialCount,
00295                                     UnsignedInt32& xintAmplitudeCount,
00296                                     UnsignedInt32& xintConstraintCount
00297                                     );
00298     UnsignedInt32 ReadBCSet(UnsignedInt32 xintIndex,
00299                             UnsignedInt32& xintBCSetID,
00300                             UnsignedInt32& xintBCSetUniqueID,
00301                             UnsignedInt32& xintBCSetAnalysisType,
00302                             UnsignedInt32& xintRestraintTypesCount,
00303                             UnsignedInt32& xintLoadTypesCount,
00304                             UnsignedInt32& xintContactPairTypesCount,
00305                             SBCSetData*& xpaBCSetRestraintData,
00306                             SBCSetData*& xpaBCSetLoadData,
00307                             SBCSetData*& xpaBCSetContactPairData
00308                             );
00309     UnsignedInt32 ReadMaterial(UnsignedInt32 xintIndex,
00310                                UnsignedInt32& xintMaterialID,
00311                                UnsignedInt32& xintMaterialUniqueID,
00312                                UnsignedInt32& xintPropertiesCount,
00313                                SMaterialData*& xpaMaterialData
00314                                );
00315     UnsignedInt32 ReadConstraint(UnsignedInt32 xintIndex,
00316                                UnsignedInt32& xintConstraintID,
00317                                UnsignedInt32& xintConstraintUniqueID,
00318                                UnsignedInt32& xintConstraintType,
00319                                UnsignedInt32& xintIndependentTypeCount,
00320                                SConstraintData*& xpaIndependentData,
00321                                UnsignedInt32& xintDependentTypeCount,
00322                                SConstraintData*& xpaDependentData
00323                                );
00324     UnsignedInt32 EndReadSimModel();
00325 
00326 
00327     UnsignedInt32 GetReadMetaData(EMetaDataOwnerType xeType,
00328         CMetaData*& xpMetaData);
00329     UnsignedInt32 GetWriteMetaData(EMetaDataOwnerType xeType,
00330         CMetaData*& xpMetaData);
00331 
00332 EErrorCode GetError() const; // ???
00333 
00334 //  enum EEndian { eLittleEndian = 0, eBigEndian = 0xFFFFFFFF };
00335     static const UnsignedInt32 mintNativeEndian;
00336     enum ECompression { eNoCompression };
00337 
00338 private:
00339     char* mstrReadFileName;
00340     char* mstrWriteFileName;
00341     char* mstrBackupFileName;
00342     UnsignedInt32 mintWriteTempFile;
00343     CubitFile mpReadFile;
00344     CubitFile mpWriteFile;
00345 EErrorCode meErrorState;
00346     UnsignedInt32 mintWriteBuffNumModels;
00347     UnsignedInt32 mintNextModelID;
00348 
00349     struct SCubitFileContentsHeader {
00350         UnsignedInt32 mintHeaderSourceEndian;
00351         UnsignedInt32 mintHeaderSchema;
00352         UnsignedInt32 mintNumModels;
00353         UnsignedInt32 mintModelTableOffset;
00354         UnsignedInt32 mintModelMetaDataOffset;
00355         UnsignedInt32 mintActiveFEModel;
00356     } mReadContents, mWriteContents;
00357     static const UnsignedInt32 mintSizeOfContents;
00358     struct SCubitFileModelEntry {
00359         UnsignedInt32 mintModelHandle;
00360         UnsignedInt32 mintModelOffset;
00361         UnsignedInt32 mintModelLength;
00362         EModelType mintModelType;
00363         UnsignedInt32 mintModelOwner;
00364         UnsignedInt32 mintModel64bitOSPad;  // make struct 64 bit word aligned
00365     } *mpaReadModels, *mpaWriteModels;
00366     static const UnsignedInt32 mintSizeOfModel;
00367   enum EModelStat { eStatNotWritten, eStatWritten, eStatDelete, eStatWriting };
00368     EModelStat* mpaReadModelStat;
00369 
00370     void WriteModelTable();
00371     UnsignedInt32 FindModel(HModel xintModel, SCubitFileModelEntry* xpaModels,
00372         UnsignedInt32 xintNumModels, UnsignedInt32& xintIndex);
00373     void CopyModel(UnsignedInt32 xintReadOffset, UnsignedInt32& xintWriteOffset,
00374         UnsignedInt32 xintLength, FILE* xpReadFile, FILE* xpWriteFile);
00375     void FreeAll();
00376 
00377     UnsignedInt32 mintFEModelIndex;
00378     UnsignedInt32 mintSimModelIndex;
00379     CFEModel* mpReadFEModel;
00380     CFEModel* mpWriteFEModel;
00381     CSimModel* mpReadSimModel;
00382     CSimModel* mpWriteSimModel;
00383     CMetaData* mpMetaData;
00384     struct {
00385         UnsignedInt32 mintNumModels;
00386         SModelData* mpaModelData;
00387     } mModelBuff;
00388 };
00389 
00390 } // namespace NCubitFile
00391 
00392 #endif
00393 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines