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
00208 class SoOutput {
00209 public:
00210
00214 SoOutput();
00215
00219 virtual ~SoOutput();
00220
00227 enum FileProperty
00228 {
00230 DefaultProperty = 0,
00232 CompressedZlib = 1
00233 };
00234
00244 virtual void setFileProperty( const FileProperty properties );
00245
00251 FileProperty getFileProperty() const;
00252
00256 virtual void setFilePointer(FILE *newFP);
00257
00264 virtual FILE * getFilePointer() const;
00265
00274 size_t fileWrite( void* buffer, size_t elemSize, size_t count );
00275
00284 int filePuts( const char* );
00285
00294 int filePutc( int );
00295
00301 SoNONUNICODE virtual SbBool openFile(const char *fileName);
00302
00308 virtual SbBool openFile( const SbString& fileName );
00309
00313 virtual void closeFile();
00314
00321 virtual void setBuffer(void *bufPointer, size_t initSize,
00322 SoOutputReallocCB *reallocFunc,
00323 int32_t offset = 0);
00324
00329 virtual SbBool getBuffer(void *&bufPointer, size_t &nBytes) const;
00330
00335 virtual size_t getBufferSize() const { return bufSize; }
00336
00340 virtual void resetBuffer();
00341
00345 virtual void setBinary(SbBool flag);
00346
00350 virtual SbBool isBinary() const { return binary; }
00351
00355 SbBool isWritingForScaleViz() const;
00356
00367 virtual void setHeaderString(const SbString &str);
00371 virtual void resetHeaderString();
00372
00376 static SbString getDefaultASCIIHeader();
00380 static SbString getDefaultBinaryHeader();
00381
00387 virtual void setFloatPrecision(int precision);
00388
00394 virtual void setDoublePrecision(int precision);
00395
00396
00397 private:
00398
00399 #ifdef _WIN32
00400 virtual SbBool openFromHandle(UINT hFile);
00401 #endif
00402 virtual void flushFile();
00403
00404
00405 enum Stage {
00406 COUNT_REFS,
00407 WRITE
00408 };
00409
00410
00411 void setStage(Stage stage) { curStage = stage; }
00412 Stage getStage() const { return curStage; }
00413
00414
00415
00416 void incrementIndent(int amount = 1)
00417 { indentLevel += amount; }
00418 void decrementIndent(int amount = 1)
00419 { indentLevel -= amount; }
00420
00421 int getIndentLevel(){ return indentLevel; }
00422
00423
00424 virtual void write(bool b);
00425 virtual void write(char c);
00426 virtual void write(unsigned char c);
00427 virtual void write(const char *s);
00428 virtual void write(const SbString &s);
00429 virtual void write(const SbName &n);
00430 virtual void write(int32_t i);
00434 virtual void write(int64_t i);
00438 virtual void write(uint32_t i);
00442 virtual void write(uint64_t i);
00443 virtual void write(short s);
00447 virtual void write(unsigned short s);
00448 virtual void write(float f);
00449 virtual void write(double d);
00450 virtual void writeBinaryArray(unsigned char *c, int length);
00451 virtual void writeBinaryArray(int32_t *l, int length);
00452 virtual void writeBinaryArray(int64_t *l, int length);
00453 virtual void writeBinaryArray(float *f, int length);
00454 virtual void writeBinaryArray(double *d, int length);
00455 virtual void writeBinaryArray(short *s, int length);
00456
00457
00458 virtual void indent();
00459
00460 private:
00461
00462 SbBool isOutFileVRML2() { return vrmlFileOut;}
00463 SbBool isOutFileX3D() { return x3dFileOut;}
00464 SbBool isHeaderWritten() { return wroteHeader;}
00465 void incrementRefOut(int amount = 1)
00466 { refOut += amount; }
00467 int getRefOut() { return refOut;}
00468
00469 SoOutput(SoOutput *dictOut);
00470
00471
00472 virtual void reset();
00473
00474
00475
00476 void setCompact(SbBool flag) { compact = flag; }
00477 SbBool isCompact() const { return compact; }
00478
00479
00480
00481 enum Annotations {
00482 ADDRESSES = (1<<0),
00483 REF_COUNTS = (1<<1)
00484 };
00485 void setAnnotation(uint32_t bits)
00486 { annotation = bits; }
00487 uint32_t getAnnotation()
00488 { return (isCompact() || isBinary()) ? 0 : annotation; }
00489 SbPList routeList;
00490
00491
00492
00493 int findReferenceIfVRML2(const SoBase *base) const;
00494
00495
00496 int addReferenceIfVRML2(const SoBase *base);
00497
00498
00499 virtual void addToVRML2Dict(const SbString name, const SoBase *base);
00500
00501
00502 virtual SoBase * findInVRML2Dict( const SbString name) const;
00503
00504
00505 virtual void addToVRMLName(const SoBase *base, const char *name);
00506
00507
00508 void writeHeader();
00509
00510 virtual char * findInVRMLName( const SoBase *base) const;
00511 SbDict *refVRMLName;
00512 SbDict *refVRML2;
00513 SbDict *PROTOToWrite;
00514 int refOut;
00515
00516 int32_t isWritingBinArrayAsMemObj() const;
00517
00518 SoOutputImpl* m_soOutputImpl;
00519
00524 struct SoOutputEntry {
00525 SbName name;
00526 int64_t offset;
00527 SoType type;
00528 };
00529
00530
00531
00532 float getIVVersion();
00533
00534 private:
00535 FILE *fp;
00536 void *zFp;
00537 SbBool toBuffer;
00538 char *tmpBuffer;
00539 void *buffer;
00540 char *curBuf;
00541 size_t bufSize;
00542 size_t tmpBufSize;
00543 SoOutputReallocCB *reallocFunc;
00544 SbBool openedHere;
00545 SbBool openedFromHandle;
00546 SbBool binary;
00547 SbBool compact;
00548 SbBool wroteHeader;
00549 int indentLevel;
00550 SbDict *refDict;
00551 SbBool borrowedDict;
00552 int refIdCount;
00553 SbBool anyRef;
00554 uint32_t annotation;
00555 Stage curStage;
00556 SbString headerString;
00557 FileProperty m_fileProperties;
00558
00559
00560
00561 static SbString padHeader(const SbString &inString);
00562
00563
00564 SbBool isToBuffer() const
00565 { return toBuffer; }
00566
00572 virtual SbBool setupFileProperties();
00573
00574
00575 size_t bytesInBuf() const
00576 { return (curBuf - static_cast<char *>(buffer) ); }
00577
00578
00579 SbBool makeRoomInBuf(size_t nBytes);
00580
00581
00582 SbBool makeRoomInTmpBuf(size_t nBytes);
00583
00584
00585
00586 int addReference(const SoBase *base);
00587
00588
00589
00590 int findReference(const SoBase *base) const;
00591
00592
00593 void convertShort(short s, char *to);
00594 void convertInt32(int32_t l, char *to);
00595 void convertInt64(int64_t l, char *to);
00596 void convertFloat(float f, char *to);
00597 void convertDouble(double d, char *to);
00598 void convertShortArray( short *from, char *to, int len);
00599 void convertInt32Array( int32_t *from, char *to, int len);
00600 void convertInt64Array( int64_t *from, char *to, int len);
00601 void convertFloatArray( float *from, char *to, int len);
00602 void convertDoubleArray( double *from, char *to, int len);
00603
00604 const char* getDoublesFormatString() const;
00605
00606 const char* getFloatsFormatString() const;
00607
00608
00609 SbBool vrmlFileOut;
00610 SbBool x3dFileOut;
00611 float m_ivVersion;
00612
00613 private:
00614 char m_floatsFmtString[16];
00615 char m_doublesFmtString[16];
00616
00617
00618 friend class SoBase;
00619 friend class SoDB;
00620 };
00621
00622 #endif
00623
00624
00625