/////////////////////////////////////////////////////////////////////////////// // Copyright (C) 2002-2025, Open Design Alliance (the "Alliance"). // All rights reserved. // // This software and its documentation and related materials are owned by // the Alliance. The software may only be incorporated into application // programs owned by members of the Alliance, subject to a signed // Membership Agreement and Supplemental Software License Agreement with the // Alliance. The structure and organization of this software are the valuable // trade secrets of the Alliance and its suppliers. The software is also // protected by copyright law and international treaty provisions. Application // programs incorporating this software must include the following statement // with their copyright notices: // // This application incorporates Open Design Alliance software pursuant to a license // agreement with Open Design Alliance. // Open Design Alliance Copyright (C) 2002-2025 by Open Design Alliance. // All rights reserved. // // By use of this software, its documentation or related materials, you // acknowledge and accept the above terms. /////////////////////////////////////////////////////////////////////////////// #ifndef _PRCRWFILER_INCLUDED_ #define _PRCRWFILER_INCLUDED_ class OdPrcCompressedFiler; #include "PrcFiler.h" #include "OdStreamBuf.h" #include "FlatMemStream.h" #include "UInt8Array.h" #include "PrcObjectId.h" SMARTPTR(OdPrcCompressedFiler); /** \details An abstract class that provides the interface for input and output operations of compressed PRC data. */ class PRC_TOOLKIT OdPrcCompressedFiler : public OdPrcFiler { protected: /** \details Create a new instance of a filer for compressed PRC data. \param authoring_version [in] An authoring version of PRC format data. */ OdPrcCompressedFiler(OdUInt32 authoring_version); public: //DOM-IGNORE-BEGIN ODPRCRX_DECLARE(OdPrcCompressedFiler) //DOM-IGNORE-END /** \details Saves the current position in the PRC file. */ virtual void savePosition() = 0; /** \details Restores the position in the PRC file that previously was saved by calling the method. */ virtual void restorePosition() = 0; /** \details Writes a set of bits to the PRC file. \param numBits [in] The number of bits to write. \param pBuf [in] A value to extract bits from. */ virtual void writeBits(OdUInt32 numBits, OdUInt8 pBuf) = 0; /** \details Writes a set of bits to the PRC file. \param numBits [in] The number of bits to write. \param pBuf [in] A pointer to a value to extract bits from. */ virtual void writeBits(OdUInt32 numBits, OdUInt8 *pBuf)= 0; /** \details Reads a set of bits from the PRC file. \param numBits [in] The number of bits. \param pBuf [out] A reference to a buffer that stores the read bit values. */ virtual void readBits(OdUInt32 numBits, OdUInt8 &pBuf) = 0; /** \details Reads a set of bits from the PRC file. \param numBits [in] The number of bits. \param pBuf [out] A pointer to a buffer that stores bit values. */ virtual void readBits(OdUInt32 numBits, OdUInt8 *pBuf) = 0; /** \details Writes an unsigned 32-bit integer value with a variable number of bits to the PRC file. \param bit_number [in] A number of bits. \param value [in] An integer value to write. */ virtual void writeUnsignedIntegerWithVariableBitNumber(OdUInt32 bit_number, OdUInt32 value) = 0; /** \details Reads an unsigned 32-bit integer value with a variable number of bits from the PRC file. \param num_of_bits [in] A number of bits. \returns The unsigned 32-bit integer value that was read. */ virtual OdUInt32 readUnsignedIntegerWithVariableBitNumber(OdUInt32 num_of_bits) = 0; /** \details Writes the number of bits needed to store an unsigned 32-bit integer value to the PRC file. \param n [in] An unsigned integer value. */ virtual void writeNumberOfBitsThenUnsignedInteger(OdUInt32 n) = 0; /** \details Reads the number of bits needed to store an unsigned 32-bit integer value from the PRC file. \returns An unsigned 32-bit integer value that contains the number of bits. */ virtual OdUInt32 readNumberOfBitsThenUnsignedInteger() = 0; /** \details Writes an unsigned integer value to the PRC file. \param i [in] An unsigned integer value to write. \param pName [in] A name of a field in the PRC file. This parameter is not currently used. */ virtual void writeUnsignedInteger(OdUInt32 i, const char* pName = 0) = 0; /** \details Reads an unsigned 32-bit integer value from the PRC file. \param pName [in] A raw pointer to the name of the field that contains the value to be read. \returns The unsigned 32-bit integer value that was read. */ virtual OdUInt32 readUnsignedInteger(const char* pName = 0) = 0; /** \details Writes a signed 32-bit integer value to the PRC file. \param i [in] A signed 32-bit integer value to write. */ virtual void writeInteger(OdInt32 i) = 0; /** \details Reads a signed 32-bit integer value from the PRC file. \returns The signed 32-bit integer value that was read. */ virtual OdInt32 readInteger() = 0; /** \details Writes a double value to the PRC file. \param i [in] A double value to write. \param pName [in] A name of a field to write the value in. This parameter is not currently used. */ virtual void writeDouble(double i, const char* pName = 0) = 0; /** \details Reads a double value from the PRC file. \param pName [in] A name of a field that contains the value to read. This parameter is not currently used. \returns The double value that was read. */ virtual double readDouble(const char* pName = 0) = 0; /** \details Writes a string value to the PRC file. \param str [in] A string value to write. \param pName [in] A name of a field to write the value in. This parameter is not currently used. */ virtual void writeString(const OdString &str, const char* pName = 0) = 0; /** \details Reads a string value from the PRC file. \param pName [in] A name of a field to read the value from. This parameter is not currently used. \returns A string value that was read. */ virtual OdString readString(const char* pName = 0) = 0; /** \details Writes a Boolean value to the PRC file. \param value [in] A Boolean value to write. \param pName [in] A name of a field to write the value in. This parameter is not currently used. */ virtual void writeBoolean(bool value, const char* pName = 0) = 0; /** \details Reads a Boolean value from the PRC file. \param pName [in] A name of a field to read the value from. This parameter is not currently used. \returns A Boolean value that was read. */ virtual bool readBoolean(const char* pName = 0) = 0; /** \details Writes 2D vector data to the PRC file. \param value [in] A 2D vector object that contains the data to write. */ virtual void writeVector2d(const OdGeVector2d &value) = 0; /** \details Reads 2D vector data from the PRC file. \returns An OdGeVector2d object that contains the read data. */ virtual OdGeVector2d readVector2d() = 0; /** \details Writes 3D vector data to the PRC file. \param value [in] A 3D vector object that contains the data to write. */ virtual void writeVector3d(const OdGeVector3d &value) = 0; /** \details Reads a 3D vector data from the PRC file. \returns An OdGeVector3d object that contains the read data. */ virtual OdGeVector3d readVector3d() = 0; /** \details Writes 2D point data to the PRC file. \param value [in] A 2D point object that contains the data to write. */ virtual void writePoint2d(const OdGePoint2d &value) = 0; /** \details Reads 2D point data from the PRC file. \return An OdGePoint2d object that contains the read data. */ virtual OdGePoint2d readPoint2d() = 0; /** \details Writes 3D point data to the PRC file. \param value [in] A 3D point object that contains the data to write. */ virtual void writePoint3d(const OdGePoint3d &value) = 0; /** \details Reads 3D point data from the PRC file. \return An OdGePoint3d object that contains the read data. */ virtual OdGePoint3d readPoint3d() = 0; /** \details Writes a character to the PRC file. \param value [in] A character to write. */ virtual void writeCharacter(char value) = 0; /** \details Reads a character from the PRC file. \returns A character value that contains the read data. */ virtual char readCharacter() = 0; /** \details Reads an entity type value from the PRC file. \returns An unsigned 32-bit integer value that contains the entity type value. \param bStepBack [in] The step back flag value. If it is equal to true, the method returns a file pointer to the position where it was before reading the entity type data. */ virtual OdUInt32 readEntityType(bool bStepBack = false) = 0; /** \details Writes the entity type value to the PRC file. \param type [in] An unsigned 32-bit value that contains the entity type to write. */ virtual void writeEntityType(OdUInt32 type) = 0; /** \details Reads a compressed entity type value from the PRC file. \param bStepBack [in] A value of the step back flag. \param isCurveOrSurface [in] A raw pointer to the flag that indicates whether the object is a curve or a surface. \returns The unsigned 32-bit integer value that contains the read compressed entity type value. \remarks If the step back flag value equals true, the method returns the file pointer to the position where it was before the reading of the entity type value. If the flag value equals false, the file pointer remains at the position it was after reading the data from the PRC file. */ virtual OdUInt32 readCompressedEntityType(bool bStepBack, bool *isCurveOrSurface = 0) = 0; /** \details Writes a compressed entity type value to the PRC file. \param isCurveType [in] A value of the flag that indicates whether the object is a curve or a surface. \param type [in] An unsigned 32-bit integer value that contains the compressed entity type. */ virtual void writeCompressedEntityType(bool isCurveType, OdUInt32 type) = 0; /** \details Reads a double value with a variable number of bits from the PRC file. \param tolerance [in] A tolerance value. \param number_of_bits [in] A number of bits. \returns The double value read from the PRC file. */ virtual double readDoubleWithVariableBitNumber(double tolerance, OdUInt32 number_of_bits) = 0; /** \details Writes a double value with a variable number of bits to the PRC file. \param value [in] A double value to write. \param tolerance [in] A tolerance value. \param number_of_bits [in] A number of bits. */ virtual void writeDoubleWithVariableBitNumber(double value, double tolerance, OdUInt32 number_of_bits) = 0; /** \details Reads a 3D point with a variable number of bits from the PRC file. \param tolerance [in] A tolerance value. \param number_of_bits [in] A number of bits. \returns The 3D point object that contains the read data. */ virtual OdGePoint3d readPoint3DWithVariableBitNumber(double tolerance, OdUInt32 number_of_bits) = 0; /** \details Writes 3D point data with a variable number of bits to the PRC file. \param point [in] A 3D point object that contains the data to write. \param tolerance [in] A tolerance value. \param number_of_bits [in] A number of bits. */ virtual void writePoint3DWithVariableBitNumber(const OdGePoint3d &point, double tolerance, OdUInt32 number_of_bits) = 0; /** \details Contains declarations of the types of bit compression strategies. */ enum CompressedBitStrategy { /** Stream compression.*/ kFromStream = 0, /** Huffman compression algorithm.*/ kUseHuffman = 1, /** No compression.*/ kNoCompression = 2 }; /** \details Reads a compressed array of integer values from the PRC file. \param points_array [out] A reference to an OdInt32Array object that stores the read values. */ virtual void readCompressedIntegerArray ( OdInt32Array &points_array ) = 0; /** \details Reads an array of characters from the PRC file. \param character_array [out] A reference to an OdInt8Array object that stores the read values. \param number_of_bits [in] A number of bits. \param bReadCompressStrategy [in] A . */ virtual void readCharacterArray ( OdInt8Array &character_array, unsigned number_of_bits, CompressedBitStrategy bReadCompressStrategy = kFromStream) = 0; /** \details Reads a signed 32-bit integer value with a variable number of bits from the PRC file. \param bit_number [in] A number of bits. \returns A signed 32-bit integer value that was read. */ virtual OdInt32 readIntegerWithVariableBitNumber(OdUInt32 bit_number) = 0; /** \details Reads an array of short integer values from the PRC file. \param normal_angle_array [out] A reference to an OdInt16Array object that stores the read values. \param number_of_bit [in] A number of bits. */ virtual void readShortArray (OdUInt16Array &normal_angle_array, OdUInt32 number_of_bit) = 0; /** \details Reads a compressed array of 32-bit integer values used as indices from the PRC file. \param integer_array [out] A reference to an OdInt32Array object that stores the read values. \param bReadCompressStrategy [in] A . */ virtual void readCompressedIndiceArray( OdInt32Array &integer_array, CompressedBitStrategy bReadCompressStrategy=kFromStream) = 0; /** \details Writes a compressed array of signed 32-bit integer values to the PRC file. \param points_array [in] A compressed array of signed 32-bit integer values to write. */ virtual void writeCompressedIntegerArray (const OdInt32Array &points_array ) = 0; /** \details Writes an array of characters to the PRC file. \param character_array [in] An array of characters to write. \param number_of_bits [in] A number of bits. \param bReadCompressStrategy [in] A . */ virtual void writeCharacterArray (const OdInt8Array &character_array, unsigned number_of_bits, CompressedBitStrategy bReadCompressStrategy = kFromStream) = 0; /** \details Writes a signed 32-bit integer value with a variable number of bits to the PRC file. \param value [in] A signed 32-bit integer value to write. \param bit_number [in] A number of bits. */ virtual void writeIntegerWithVariableBitNumber(OdInt32 value, OdUInt32 bit_number) = 0; /** \details Writes an array of unsigned short integer values to the PRC file. \param normal_angle_array [in] An array of unsigned short integer values to write. \param number_of_bit [in] A number of bits. */ virtual void writeShortArray (const OdUInt16Array &normal_angle_array, OdUInt32 number_of_bit) = 0; /** \details Writes a compressed array of signed 32-bit integer values to the PRC file. \param integer_array [in] A compressed array of singed 32-bit integer values to write. \param bReadCompressStrategy [in] A . */ virtual void writeCompressedIndiceArray(const OdInt32Array &integer_array, CompressedBitStrategy bReadCompressStrategy=kFromStream) = 0; }; /** \details Reads an array of double values from a PRC file. \param array [out] A reference to an array of double values to store read data. \param pStream [in] A pointer to an input file stream. */ void readDoubleArray(OdGeDoubleArray &array, OdPrcCompressedFiler *pStream); /** \details Reads an array of double values from a PRC file. \param array [out] A reference to an array of double values to store read data. \param pStream [in] A pointer to an input file stream. \param num [in] A number of elements to read. */ void readDoubleArray(OdGeDoubleArray &array, OdPrcCompressedFiler *pStream, OdUInt32 num); /** \details Reads an array of unsigned 32-bit integer values from a PRC file. \param array [out] A reference to an array of unsigned 32-bit integer values to store read data. \param pStream [in] A pointer to an input file stream. */ void readUInt32Array(OdUInt32Array &array, OdPrcCompressedFiler *pStream); /** \details Reads an array of 32-bit integer values from a PRC file. \param array [out] A reference to an array of 32-bit integer values to store read data. \param pStream [in] A pointer to an input file stream. */ void readInt32Array(OdInt32Array &array, OdPrcCompressedFiler *pStream); /** \details Reads an array of 32-bit integer values from a PRC file. \param array [out] A reference to an array of 32-bit integer values to store read data. \param pStream [in] A pointer to an input file stream. \param num [in] A number of elements to read. */ void readInt32Array(OdInt32Array &array, OdPrcCompressedFiler *pStream, OdUInt32 num); /** \details Reads an array of strings from a PRC file. \param array [out] A reference to an array of string values to store read data. \param pStream [in] A pointer to an input file stream. */ void readStringArray(OdStringArray &array, OdPrcCompressedFiler *pStream); /** \details Reads an array of 3D vectors from a PRC file. \param array [out] A reference to an array of 3D vectors to store read data. \param pStream [in] A pointer to an input file stream. */ void readVector3dArray(OdGeVector3dArray &array, OdPrcCompressedFiler *pStream); /** \details Reads an array of 3D vectors from a PRC file. \param array [out] A reference to an array of 3D vectors to store read data. \param pStream [in] A pointer to an input file stream. \param num [in] A number of elements. */ void readVector3dArray(OdGeVector3dArray &array, OdPrcCompressedFiler *pStream, OdUInt32 num); /** \details Reads an array of 2D points from a PRC file. \param array [out] A reference to an array of 2D points to store read data. \param pStream [in] A pointer to an input file stream. */ void readPoint2dArray(OdGePoint2dArray &array, OdPrcCompressedFiler *pStream); /** \details Reads an array of 2D points from a file. \param array [out] A reference to an array of 2D points to store read data. \param pStream [in] A pointer to an input file stream. \param num [in] A number of elements. */ void readPoint2dArray(OdGePoint2dArray &array, OdPrcCompressedFiler *pStream, OdUInt32 num); /** \details Reads an array of 3D points from a file. \param array [out] A reference to an array of 3D points to store read data. \param pStream [in] A pointer to an input file stream. */ void readPoint3dArray(OdGePoint3dArray &array, OdPrcCompressedFiler *pStream); /** \details Reads an array of 3D points from a file. \param array [out] A reference to an array of 3D points to store read data. \param pStream [in] A pointer to an input file stream. \param num [in] A number of elements. */ void readPoint3dArray(OdGePoint3dArray &array, OdPrcCompressedFiler *pStream, OdUInt32 num); /** \details Writes an array of double values to a stream. \param array [in] An array of double values to write. \param pStream [in] A pointer to an output stream. */ void writeDoubleArray(const OdGeDoubleArray &array, OdPrcCompressedFiler *pStream); /** \details Writes an array of double values to a stream. \param array [in] An array of double values to write. \param pStream [in] A pointer to an output stream. \param num [in] A number of elements. */ void writeDoubleArray(const OdGeDoubleArray &array, OdPrcCompressedFiler *pStream, OdUInt32 num); /** \details Writes an array of unsigned 32-bit integer values to a stream. \param array [in] An array of unsigned 32-bit integer values to write. \param pStream [in] A pointer to an output stream. */ void writeUInt32Array(const OdUInt32Array &array, OdPrcCompressedFiler *pStream); /** \details Writes an array of 32-bit integer values to a stream. \param array [in] An array of 32-bit integer values to write. \param pStream [in] A pointer to an output stream. */ void writeInt32Array(const OdInt32Array &array, OdPrcCompressedFiler *pStream); /** \details Writes an array of 32-bit integer values to a stream. \param array [in] An array of 32-bit integer values to write. \param pStream [in] A pointer to an output stream. \param num [in] A number of elements. */ void writeInt32Array(const OdInt32Array &array, OdPrcCompressedFiler *pStream, OdUInt32 num); /** \details Writes an array of strings to a stream. \param array [in] An array of string values to write. \param pStream [in] A pointer to an output stream. */ void writeStringArray(const OdStringArray &array, OdPrcCompressedFiler *pStream); /** \details Writes an array of 3D vectors to a stream. \param array [in] An array of 3D vectors to write. \param pStream [in] A pointer to an output stream. */ void writeVector3dArray(const OdGeVector3dArray &array, OdPrcCompressedFiler *pStream); /** \details Writes an array of 3D vectors to a stream. \param array [in] An array of 3D vectors to write. \param pStream [in] A pointer to an output stream. \param num [in] A number of elements. */ void writeVector3dArray(const OdGeVector3dArray &array, OdPrcCompressedFiler *pStream, OdUInt32 num); /** \details Writes an array of 2D points to a stream. \param array [in] An array of 2D points to write. \param pStream [in] A pointer to an output stream. */ void writePoint2dArray(const OdGePoint2dArray &array, OdPrcCompressedFiler *pStream); /** \details Writes an array of 2D points to a stream. \param array [in] An array of 2D points to write. \param pStream [in] A pointer to an output stream. \param num [in] A number of elements. */ void writePoint2dArray(const OdGePoint2dArray &array, OdPrcCompressedFiler *pStream, OdUInt32 num); /** \details Writes an array of 3D points to a stream. \param array [in] An array of 3D points to write. \param pStream [in] A pointer to an output stream. */ void writePoint3dArray(const OdGePoint3dArray &array, OdPrcCompressedFiler *pStream); /** \details Writes an array of 3D points to a stream. \param array [in] An array of 3D points to write. \param pStream [in] A pointer to an output stream. \param num [in] A number of elements. */ void writePoint3dArray(const OdGePoint3dArray &array, OdPrcCompressedFiler *pStream, OdUInt32 num); /** \details Reads an array of double values from a compressed data stream and converts it to a . \param array [out] A reference to an to store read data. \param pStream [in] A pointer to an input compressed data stream. */ void readFloatArrayAsDoubleArray(OdFloatArray &array, OdPrcCompressedFiler *pStream); /** \details Reads an array of double values from a compressed data stream and converts it to a . \param array [out] A reference to an to store read data. \param pStream [in] A pointer to an input compressed data stream. \param num [in] A quantity of values to be read from a data stream. */ void readFloatArrayAsDoubleArray(OdFloatArray &array, OdPrcCompressedFiler *pStream, OdUInt32 num); /** \details Writes an as an array of double values to a compressed data stream. \param array [in] A to be written. \param pStream [in] A pointer to an output compressed data stream. \remarks Each element of the input float array is converted to a double value before writing to the data stream. */ void writeFloatArrayAsDoubleArray(const OdFloatArray &array, OdPrcCompressedFiler *pStream); /** \details Writes an as an array of double values to a compressed data stream. \param array [in] A to be written. \param pStream [in] A pointer to an output compressed data stream. \param num [in] A quantity of values to be written to a data stream. \remarks Each element of the input float array is converted to a double value before writing to the data stream. */ void writeFloatArrayAsDoubleArray(const OdFloatArray &array, OdPrcCompressedFiler *pStream, OdUInt32 num); /** \details A template function that reads an array of a specified data type from a compressed data stream. \param array [out] A reference to an array to store the read data. \param pStream [in] A pointer to an input compressed data stream. */ template void readArray(T &array, OdPrcCompressedFiler *pStream) { OdUInt32 i, num; num = pStream->readUnsignedInteger("ArraySize"); array.resize(num); for (i=0; i void writeArray(T &array, OdPrcCompressedFiler *pStream) { OdUInt32 i, num = array.size(); pStream->writeUnsignedInteger(num, "ArraySize"); for (i=0; i void readPtrArray(OdArray< OdSmartPtr > &array, OdPrcCompressedFiler *pStream) { OdUInt32 i, num; num = pStream->readUnsignedInteger("ArraySize"); array.resize(num); for (i = 0; i < num; ++i) { array[i] = T::createObject(); array[i]->prcIn(pStream); } } /** \details A template function that writes an array of a specified data type to a compressed data type. Elements of the array to be written are represented with smart pointers. \param array [in] An array of smart pointers that refer to elements to be written. \param pStream [in] A pointer to an output compressed data stream. */ template void writePtrArray(OdArray< OdSmartPtr > &array, OdPrcCompressedFiler *pStream) { OdUInt32 i, num = array.size(); pStream->writeUnsignedInteger(num, "ArraySize"); for (i=0; iprcOut(pStream); } } /** \details A template function that writes an array of objects to a compressed data stream. Objects that should be written are represented with object identifiers. \param array [in] An that represent objects to be written. \param pStream [in] A pointer to an output compressed data stream. */ template void writeIdsArray(const OdPrcObjectIdArray &array, OdPrcCompressedFiler *pStream) { OdUInt32 i, num = array.size(); pStream->writeUnsignedInteger(num, "ArraySize"); for (i=0; i pObj = array[i].safeOpenObject(); // to check that id has proper type. pObj->prcOut(pStream); } } /** \details A template function that reads an array of objects from a compressed data stream and creates an array of identifiers that refer to read objects. \param array [out] A reference to an that refer to read objects. \param pStream [in] A pointer to an input compressed data stream. */ template void readIdsArray(OdPrcObjectIdArray &array, OdPrcCompressedFiler *pStream) { OdUInt32 i, num; num = pStream->readUnsignedInteger("ArraySize"); array.resize(num); for (i=0; i pObj = T::createObject(); pObj->prcIn(pStream); array[i] = pObj->objectId(); } } /** \details A template function that reads data from a compressed data stream and creates an array of read data elements. \param array [out] A reference to an array to store read data. \param pStream [in] A pointer to an input compressed data stream. */ template void readBaseArray(TArr &array, OdPrcCompressedFiler *pStream) { OdUInt32 i, num; num = pStream->readUnsignedInteger("ArraySize"); array.resize(num); for (i = 0; i