/////////////////////////////////////////////////////////////////////////////// // 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. /////////////////////////////////////////////////////////////////////////////// // // JsonServerBaseImpl.cpp // #include "OdaCommon.h" #include "JsonServerBaseImpl.h" #include "DbBaseDatabase.h" OdGLES2JsonServerBaseImpl::OdGLES2JsonServerBaseImpl(const OdDbBaseDatabase * pDb) : m_nIdent(0) , m_pDbPE(nullptr) , m_bClientDependentSectionOnly(false) , m_bEmptyMetaFile(true) , m_bEnableFaces(true) , m_pszTmpBuf(nullptr) , m_lenTmpBuf(0) { setDatabase(pDb); } void OdGLES2JsonServerBaseImpl::setDatabase(const OdDbBaseDatabase* pDb) { if (pDb) m_pDbPE = OdDbBaseDatabasePE::cast(pDb); else m_pDbPE = nullptr; } void OdGLES2JsonServerBaseImpl::append(OdAnsiString& to, OdDbStub* from) const { if (m_pDbPE) OdTrVisUniqueID::DefUIDTransformer::append(to, (OdUInt64)m_pDbPE->getHandle(from)); else OdTrVisUniqueID::DefUIDTransformer::append(to, from); } void OdGLES2JsonServerBaseImpl::IncreaseNesting(const char* pLevelName, const OdGLES2JsonServer::JsonType& JsonType) { ODFMTBEG((odStrLenA(pLevelName) > 0 ? odStrLenA(pLevelName) + 4 : 1)) odStrLenA(pLevelName) > 0 ? (JsonType == OdGLES2JsonServer::kArray ? "\"%s\":[" : "\"%s\":{") : (JsonType == OdGLES2JsonServer::kArray ? "[" : "{"), pLevelName ODFMTEND() ident(NULL, m_sTmpBuf.c_str(), JsonType); m_nIdent += 2; } void OdGLES2JsonServerBaseImpl::DecreaseNesting(const char* pLevelName, const OdGLES2JsonServer::JsonType& JsonType) { m_nIdent -= 2; ODFMTBEG(2) //"}", pLevelName (JsonType == OdGLES2JsonServer::kArray ? "]" : "}") ODFMTEND() ident(NULL, m_sTmpBuf.c_str(), JsonType); } void OdGLES2JsonServerBaseImpl::DropId(const char* pTagName, OdUInt64 data, OdTrVisUniqueID* pId, OdInt32 enAdv) { if (pId && data > OdUInt64(100)) // is not an address { m_sTmpBuf = pId->transform(*this); ident(pTagName, m_sTmpBuf.c_str(), OdGLES2JsonServer::kType); return; } ODA_ASSERT_ONCE(data <= OdUInt64(100)); OdGLES2JsonServer::DropId(pTagName, data, pId, enAdv); // DropUInt64(pTagName, data); } void OdGLES2JsonServerBaseImpl::DropBoolean(const char* pTagName, bool data) { //DropUInt32(pTagName, (data) ? 1 : 0); m_sTmpBuf = data ? "true" : "false"; ident(pTagName, m_sTmpBuf.c_str(), OdGLES2JsonServer::kNumber); } void OdGLES2JsonServerBaseImpl::DropUInt8(const char* pTagName, OdUInt8 data) { DropUInt32(pTagName, data); } void OdGLES2JsonServerBaseImpl::DropUInt32(const char* pTagName, OdUInt32 data) { ODFMTBEG(16) "%u", (unsigned)data ODFMTEND() ident(pTagName, m_sTmpBuf.c_str(), OdGLES2JsonServer::kNumber); } void OdGLES2JsonServerBaseImpl::DropUInt64(const char* pTagName, OdUInt64 data) { ODFMTBEG(32) #if (OD_SIZEOF_LONG == 4) || defined(__APPLE__) "%" PRIu64, (unsigned long long)data #else "%" PRIu64, data #endif ODFMTEND() ident(pTagName, m_sTmpBuf.c_str(), OdGLES2JsonServer::kNumber); } void OdGLES2JsonServerBaseImpl::DropInt32(const char* pTagName, OdInt32 data) { ODFMTBEG(10) "%d", (int)data ODFMTEND() ident(pTagName, m_sTmpBuf.c_str(), OdGLES2JsonServer::kNumber); } void OdGLES2JsonServerBaseImpl::DropChars(const char* pTagName, const char* pStr) { m_sTmpBuf = pStr; m_sTmpBuf.replace("<", "<"); m_sTmpBuf.replace(">", ">"); m_sTmpBuf.replace("\n", " "); ident(pTagName, m_sTmpBuf.c_str(), OdGLES2JsonServer::kString); } void OdGLES2JsonServerBaseImpl::DropString(const char* pTagName, const OdString& pStr) { OdAnsiCharArray utf8Str(pStr.getLength() * 4 + 1, 1); OdCharMapper::unicodeToUtf8(pStr.c_str(), pStr.getLength(), utf8Str); DropChars(pTagName, utf8Str.getPtr()); } void OdGLES2JsonServerBaseImpl::DropInts(const char* pTagName, OdUInt32 nData, const OdUInt16* pData) { ODA_ASSERT_ONCE(nData && pData); ODFMTFORBEG(16) index ? ",%d" : "%d" , pData[index] ODFMTEND() ident(pTagName, m_sTmpBuf.c_str(), OdGLES2JsonServer::kArray); } void OdGLES2JsonServerBaseImpl::DropUInts(const char* pTagName, OdUInt32 nData, const OdUInt32* pData) { ODA_ASSERT_ONCE(nData && pData); ODFMTFORBEG(32) #if OD_SIZEOF_LONG == 4 index ? ",%lu" : "%lu", pData[index] #else index ? ",%u" : "%u", pData[index] #endif ODFMTEND() ident(pTagName, m_sTmpBuf.c_str(), OdGLES2JsonServer::kArray); } void OdGLES2JsonServerBaseImpl::DropFloats(const char* pTagName, OdUInt32 nData, const float* pData) { ODA_ASSERT_ONCE(nData && !(nData % 3)); // test if (odStrCmpA(pTagName, "ArrayData") || !nData || (nData % 3) || (Od_abs(pData[0]) < 10000 && Od_abs(pData[1]) < 10000 && Od_abs(pData[2]) < 10000)) { ODA_ASSERT_ONCE(nData && pData); ODFMTFORBEG(32) ODFLTFMT("%s", pData[index],), index ? "," : "", pData[index] ODFMTEND() ident(pTagName, m_sTmpBuf.c_str(), OdGLES2JsonServer::kArray); return; } float val, offs[3]; #if !defined(__BORLANDC__) && !defined(__hpux) offs[0] = ceilf(pData[0]) - 1.0f; offs[1] = ceilf(pData[1]) - 1.0f; offs[2] = ceilf(pData[2]) - 1.0f; // by first #else // float-mathematics is missing in Builder offs[0] = pData[0]; offs[1] = pData[1]; offs[2] = pData[2]; #endif DropFloat3("ArrayOffset", offs[0], offs[1], offs[2]); ODA_ASSERT_ONCE(nData && pData); ODFMTFORBEGEX(16, val = pData[index] - offs[index % 3]) //index ? ",%g" : "%g" , pData[index] - offs[index % 3] ODFLTFMT("%s", val,), index ? "," : "", val ODFMTEND() ident(pTagName, m_sTmpBuf.c_str(), OdGLES2JsonServer::kType); } void OdGLES2JsonServerBaseImpl::DropFloat(const char* pTagName, float data) { ODFMTBEG(32) //"%g", data ODFLTFMT(, data,), data ODFMTEND() ident(pTagName, m_sTmpBuf.c_str(), OdGLES2JsonServer::kNumber); } void OdGLES2JsonServerBaseImpl::DropFloat2(const char* pTagName, float data1, float data2) { ODFMTBEG(64) //"%g, %g", data1, data2 ODFLTFMT(, data1,), data1 ODFMTADD() ODFLTFMT(", ", data2,), data2 ODFMTEND() ident(pTagName, m_sTmpBuf.c_str(), OdGLES2JsonServer::kArray); } void OdGLES2JsonServerBaseImpl::DropFloat3(const char* pTagName, float data1, float data2, float data3) { ODFMTBEG(96) //"%g, %g, %g", data1, data2, data3 ODFLTFMT(, data1,), data1 ODFMTADD() ODFLTFMT(", ", data2,), data2 ODFMTADD() ODFLTFMT(", ", data3,), data3 ODFMTEND() ident(pTagName, m_sTmpBuf.c_str(), OdGLES2JsonServer::kArray); } void OdGLES2JsonServerBaseImpl::DropFloat4(const char* pTagName, float data1, float data2, float data3, float data4) { ODFMTBEG(128) //"%g, %g, %g, %g", data1, data2, data3, data4 ODFLTFMT(, data1,), data1 ODFMTADD() ODFLTFMT(", ", data2,), data2 ODFMTADD() ODFLTFMT(", ", data3,), data3 ODFMTADD() ODFLTFMT(", ", data4,), data4 ODFMTEND() ident(pTagName, m_sTmpBuf.c_str(), OdGLES2JsonServer::kArray); } void OdGLES2JsonServerBaseImpl::DropUInt8RGB(const char* pTagName, OdUInt8 data1, OdUInt8 data2, OdUInt8 data3, OdUInt8 data4) { ODFMTBEG(64) "%u, %u, %u, %u", (unsigned)data1, (unsigned)data2, (unsigned)data3, (unsigned)data4 ODFMTEND() ident(pTagName, m_sTmpBuf.c_str(), OdGLES2JsonServer::kNumber); } void OdGLES2JsonServerBaseImpl::DropMatrix(const char* pTagName, const OdGeMatrix3d& data) { ODFMTBEG(512) //"%g, %g, %g, %g, %g, %g, %g, %g, %g, %g, %g, %g, %g, %g, %g, %g", //data.entry[0][0], data.entry[0][1], data.entry[0][2], data.entry[0][3], //data.entry[1][0], data.entry[1][1], data.entry[1][2], data.entry[1][3], //data.entry[2][0], data.entry[2][1], data.entry[2][2], data.entry[2][3], //data.entry[3][0], data.entry[3][1], data.entry[3][2], data.entry[3][3] ODFLTFMT(, data.entry[0][0],), (double)(float)data.entry[0][0] ODFMTADD() ODFLTFMT(", ", data.entry[0][1],), (double)(float)data.entry[0][1] ODFMTADD() ODFLTFMT(", ", data.entry[0][2],), (double)(float)data.entry[0][2] ODFMTADD() ODFLTFMT(", ", data.entry[0][3],), (double)(float)data.entry[0][3] ODFMTADD() ODFLTFMT(", ", data.entry[1][0],), (double)(float)data.entry[1][0] ODFMTADD() ODFLTFMT(", ", data.entry[1][1],), (double)(float)data.entry[1][1] ODFMTADD() ODFLTFMT(", ", data.entry[1][2],), (double)(float)data.entry[1][2] ODFMTADD() ODFLTFMT(", ", data.entry[1][3],), (double)(float)data.entry[1][3] ODFMTADD() ODFLTFMT(", ", data.entry[2][0],), (double)(float)data.entry[2][0] ODFMTADD() ODFLTFMT(", ", data.entry[2][1],), (double)(float)data.entry[2][1] ODFMTADD() ODFLTFMT(", ", data.entry[2][2],), (double)(float)data.entry[2][2] ODFMTADD() ODFLTFMT(", ", data.entry[2][3],), (double)(float)data.entry[2][3] ODFMTADD() ODFLTFMT(", ", data.entry[3][0],), (double)(float)data.entry[3][0] ODFMTADD() ODFLTFMT(", ", data.entry[3][1],), (double)(float)data.entry[3][1] ODFMTADD() ODFLTFMT(", ", data.entry[3][2],), (double)(float)data.entry[3][2] ODFMTADD() ODFLTFMT(", ", data.entry[3][3],), (double)(float)data.entry[3][3] ODFMTEND() ident(pTagName, m_sTmpBuf.c_str(), OdGLES2JsonServer::kArray); } void OdGLES2JsonServerBaseImpl::DropBinaryStream(const char* pTagName, const OdUInt8* pData, OdUInt32 nData) { ODFMTFORBEG(4) "%02X", pData[index] ODFMTEND() ident(pTagName, m_sTmpBuf.c_str(), OdGLES2JsonServer::kType); } void OdGLES2JsonServerBaseImpl::DropDbOwning(const char* pTagName, OdTrVisOwning owningId) { // possible via paper object for example //ODA_ASSERT_ONCE(pDbStub); if (owningId == kTrVisNullId) return; m_sTmpBuf.empty(); append(m_sTmpBuf, OdTrVisIdToPtr(OdDbStub, owningId)); ident(pTagName, m_sTmpBuf, OdGLES2JsonServer::kType); } bool OdGLES2JsonServerBaseImpl::UpdateClientDependentSectionOnly() const { return m_bClientDependentSectionOnly; }