00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051 #ifndef _SO_OUTPUT_
00052 #define _SO_OUTPUT_
00053
00054 #include <Inventor/misc/SoBasic.h>
00055 #include <Inventor/SbDict.h>
00056 #include <Inventor/SbString.h>
00057 #include <Inventor/SoType.h>
00058
00059 class SoBase;
00060 class SoOutputImpl;
00061
00062 typedef void *SoOutputReallocCB(void *ptr, size_t newSize);
00063
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00091
00185 class SoOutput {
00186 public:
00187
00191 SoOutput();
00192
00196 virtual ~SoOutput();
00197
00204 enum FileProperty
00205 {
00207 DefaultProperty = 0,
00209 CompressedZlib = 1
00210 };
00211
00221 virtual void setFileProperty( const FileProperty properties );
00222
00228 FileProperty getFileProperty() const;
00229
00233 virtual void setFilePointer(FILE *newFP);
00234
00241 virtual FILE * getFilePointer() const;
00242
00251 size_t fileWrite( void* buffer, size_t elemSize, size_t count );
00252
00261 int filePuts( const char* );
00262
00271 int filePutc( int );
00272
00278 SoNONUNICODE virtual SbBool openFile(const char *fileName);
00279
00285 virtual SbBool openFile( const SbString& fileName );
00286
00290 virtual void closeFile();
00291
00298 virtual void setBuffer(void *bufPointer, size_t initSize,
00299 SoOutputReallocCB *reallocFunc,
00300 int32_t offset = 0);
00301
00306 virtual SbBool getBuffer(void *&bufPointer, size_t &nBytes) const;
00307
00312 virtual size_t getBufferSize() const { return bufSize; }
00313
00317 virtual void resetBuffer();
00318
00322 virtual void setBinary(SbBool flag);
00323
00327 virtual SbBool isBinary() const { return binary; }
00328
00332 SbBool isWritingForScaleViz() const;
00333
00344 virtual void setHeaderString(const SbString &str);
00348 virtual void resetHeaderString();
00349
00353 static SbString getDefaultASCIIHeader();
00357 static SbString getDefaultBinaryHeader();
00358
00364 virtual void setFloatPrecision(int precision);
00365
00371 virtual void setDoublePrecision(int precision);
00372
00373
00374 private:
00375
00376 #ifdef _WIN32
00377 virtual SbBool openFromHandle(UINT hFile);
00378 #endif
00379 virtual void flushFile();
00380
00381
00382 enum Stage {
00383 COUNT_REFS,
00384 WRITE
00385 };
00386
00387
00388 void setStage(Stage stage) { curStage = stage; }
00389 Stage getStage() const { return curStage; }
00390
00391
00392
00393 void incrementIndent(int amount = 1)
00394 { indentLevel += amount; }
00395 void decrementIndent(int amount = 1)
00396 { indentLevel -= amount; }
00397
00398 int getIndentLevel(){ return indentLevel; }
00399
00400
00401 virtual void write(bool b);
00402 virtual void write(char c);
00403 virtual void write(unsigned char c);
00404 virtual void write(const char *s);
00405 virtual void write(const SbString &s);
00406 virtual void write(const SbName &n);
00407 virtual void write(int32_t i);
00411 virtual void write(int64_t i);
00415 virtual void write(uint32_t i);
00419 virtual void write(uint64_t i);
00420 virtual void write(short s);
00424 virtual void write(unsigned short s);
00425 virtual void write(float f);
00426 virtual void write(double d);
00427 virtual void writeBinaryArray(unsigned char *c, int length);
00428 virtual void writeBinaryArray(int32_t *l, int length);
00429 virtual void writeBinaryArray(int64_t *l, int length);
00430 virtual void writeBinaryArray(float *f, int length);
00431 virtual void writeBinaryArray(double *d, int length);
00432 virtual void writeBinaryArray(short *s, int length);
00433
00434
00435 virtual void indent();
00436
00437 private:
00438
00439 SbBool isOutFileVRML2() { return vrmlFileOut;}
00440 SbBool isOutFileX3D() { return x3dFileOut;}
00441 SbBool isHeaderWritten() { return wroteHeader;}
00442 void incrementRefOut(int amount = 1)
00443 { refOut += amount; }
00444 int getRefOut() { return refOut;}
00445
00446 SoOutput(SoOutput *dictOut);
00447
00448 virtual void writeLargeBinaryArray(unsigned char *c, size_t length);
00449
00450
00451 virtual void reset();
00452
00453
00454
00455 void setCompact(SbBool flag) { compact = flag; }
00456 SbBool isCompact() const { return compact; }
00457
00458
00459
00460 enum Annotations {
00461 ADDRESSES = (1<<0),
00462 REF_COUNTS = (1<<1)
00463 };
00464 void setAnnotation(uint32_t bits)
00465 { annotation = bits; }
00466 uint32_t getAnnotation()
00467 { return (isCompact() || isBinary()) ? 0 : annotation; }
00468 SbPList routeList;
00469
00470
00471
00472 int findReferenceIfVRML2(const SoBase *base) const;
00473
00474
00475 int addReferenceIfVRML2(const SoBase *base);
00476
00477
00478 virtual void addToVRML2Dict(const SbString name, const SoBase *base);
00479
00480
00481 virtual SoBase * findInVRML2Dict( const SbString name) const;
00482
00483
00484 virtual void addToVRMLName(const SoBase *base, const char *name);
00485
00486
00487 void writeHeader();
00488
00489 virtual char * findInVRMLName( const SoBase *base) const;
00490 SbDict *refVRMLName;
00491 SbDict *refVRML2;
00492 SbDict *PROTOToWrite;
00493 int refOut;
00494
00495 int32_t isWritingBinArrayAsMemObj() const;
00496
00497 SoOutputImpl* m_soOutputImpl;
00498
00503 struct SoOutputEntry {
00504 SbName name;
00505 int64_t offset;
00506 SoType type;
00507 };
00508
00509
00510
00511 float getIVVersion();
00512
00513 private:
00514 FILE *fp;
00515 void *zFp;
00516 SbBool toBuffer;
00517 char *tmpBuffer;
00518 void *buffer;
00519 char *curBuf;
00520 size_t bufSize;
00521 size_t tmpBufSize;
00522 SoOutputReallocCB *reallocFunc;
00523 SbBool openedHere;
00524 SbBool openedFromHandle;
00525 SbBool binary;
00526 SbBool compact;
00527 SbBool wroteHeader;
00528 int indentLevel;
00529 SbDict *refDict;
00530 SbBool borrowedDict;
00531 int refIdCount;
00532 SbBool anyRef;
00533 uint32_t annotation;
00534 Stage curStage;
00535 SbString headerString;
00536 FileProperty m_fileProperties;
00537
00538
00539
00540 static SbString padHeader(const SbString &inString);
00541
00542
00543 SbBool isToBuffer() const
00544 { return toBuffer; }
00545
00551 virtual SbBool setupFileProperties();
00552
00553
00554 size_t bytesInBuf() const
00555 { return (curBuf - static_cast<char *>(buffer) ); }
00556
00557
00558 SbBool makeRoomInBuf(size_t nBytes);
00559
00560
00561 SbBool makeRoomInTmpBuf(size_t nBytes);
00562
00563
00564
00565 int addReference(const SoBase *base);
00566
00567
00568
00569 int findReference(const SoBase *base) const;
00570
00571
00572 void convertShort(short s, char *to);
00573 void convertInt32(int32_t l, char *to);
00574 void convertInt64(int64_t l, char *to);
00575 void convertFloat(float f, char *to);
00576 void convertDouble(double d, char *to);
00577 void convertShortArray( short *from, char *to, int len);
00578 void convertInt32Array( int32_t *from, char *to, int len);
00579 void convertInt64Array( int64_t *from, char *to, int len);
00580 void convertFloatArray( float *from, char *to, int len);
00581 void convertDoubleArray( double *from, char *to, int len);
00582
00583 const char* getDoublesFormatString() const;
00584
00585 const char* getFloatsFormatString() const;
00586
00587
00588 SbBool vrmlFileOut;
00589 SbBool x3dFileOut;
00590 float m_ivVersion;
00591
00592 private:
00593 char m_floatsFmtString[16];
00594 char m_doublesFmtString[16];
00595
00596
00597 friend class SoBase;
00598 friend class SoDB;
00599 };
00600
00601 #endif
00602
00603
00604