/////////////////////////////////////////////////////////////////////////////// // 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. /////////////////////////////////////////////////////////////////////////////// // TrGL2 renderer local client #include "OdaCommon.h" #include "Gi/GiPlotStyleDefs.h" #include "Gs/GsHighlightData.h" #include "TrVecLocalSharingProvider.h" #include "TrVecLocalRenditionGsClient.h" // OdTrVecStateBranchGsClient OdTrVisStateBranchPtr OdTrVecStateBranchGsClient::stateBranchGetPtr(OdTrVisStateBranchId branchId) const { return OdTrVisIdToPtr(void, branchId); } OdTrVisStateBranchId OdTrVecStateBranchGsClient::stateBranchId(OdTrVisStateBranchPtr pStateBranch) const { return (OdTrVisStateBranchId)OdTrVisPtrToId(pStateBranch); } void OdTrVecStateBranchGsClient::stateBranchLock(OdTrVisStateBranchId branchId) const { OdTrVisIdToPtr(OdGsStateBranch, branchId)->addRef(); } bool OdTrVecStateBranchGsClient::stateBranchUnlock(OdTrVisStateBranchId branchId) const { return OdTrVisIdToPtr(OdGsStateBranch, branchId)->release(); } bool OdTrVecStateBranchGsClient::stateBranchIsEmpty(OdTrVisStateBranchPtr pStateBranchIn) const { const OdGsStateBranch *pStateBranch = reinterpret_cast(pStateBranchIn); return pStateBranch->isEmpty(); } bool OdTrVecStateBranchGsClient::stateBranchHasMarkers(OdTrVisStateBranchPtr pStateBranchIn) const { const OdGsStateBranch *pStateBranch = reinterpret_cast(pStateBranchIn); return !pStateBranch->markersEmpty(); } OdTrVisStateBranchPtr OdTrVecStateBranchGsClient::stateBranchGetChild(OdTrVisStateBranchPtr pStateBranchIn, OdTrVisOwning childId) const { const OdGsStateBranch *pStateBranch = reinterpret_cast(pStateBranchIn); return const_cast(pStateBranch)->findChild(OdTrVisIdToPtr(OdDbStub, childId)); } OdTrVisStateChildIt OdTrVecStateBranchGsClient::stateBranchNextChild(OdTrVisStateBranchPtr pStateBranchIn, OdTrVisStateChildIt it, OdTrVisStateBranchId *pChildId) const { const OdGsStateBranch *pStateBranch = reinterpret_cast(pStateBranchIn); OdGsStateBranchPtrArray::const_iterator nIt = nullptr; if (it) { nIt = reinterpret_cast(it); nIt++; if (nIt == pStateBranch->aChild().end()) nIt = nullptr; } else if (!pStateBranch->aChild().isEmpty()) nIt = pStateBranch->aChild().begin(); if (pChildId && nIt) *pChildId = OdTrVisPtrToId(nIt->get()); return reinterpret_cast(nIt); } OdTrVisStateMarkerPtr OdTrVecStateBranchGsClient::stateBranchHasMarker(OdTrVisStateBranchPtr pStateBranchIn, OdTrVisGsMarker gsMarker) const { const OdGsStateBranch *pStateBranch = reinterpret_cast(pStateBranchIn); OdGsMarkerSet::const_iterator it; if (!pStateBranch->hasMarker((OdGsMarker)gsMarker, it)) return nullptr; return &(*it); } template void call_dest(DataType& data) { (void)data; //warning C4100 on old msvc compilers data.~DataType(); } OdTrVisStateMarkerIt OdTrVecStateBranchGsClient::stateBranchNextMarker(OdTrVisStateBranchPtr pStateBranchIn, OdTrVisStateMarkerIt it, OdTrVisGsMarker *pMarkerId) const { const OdGsStateBranch *pStateBranch = reinterpret_cast(pStateBranchIn); OdGsMarkerSet::const_iterator *nIt = NULL; static_assert(sizeof(OdGsMarkerSet::const_iterator) <= sizeof(OdTrVisStateMarkerIt), "Wrong OdTrVisStateMarkerIt size"); constexpr size_t itsz = sizeof(OdGsMarkerSet::const_iterator); constexpr size_t exsz = sizeof(OdTrVisStateMarkerIt) - itsz; if (!it.isNull()) { nIt = reinterpret_cast(it.m_pData + (exsz >> 3)); (*nIt)++; } else if (!pStateBranch->markers().empty()) { nIt = reinterpret_cast(it.m_pData + (exsz >> 3)); new (nIt) OdGsMarkerSet::const_iterator(); *nIt = pStateBranch->markers().begin(); } if (pMarkerId && nIt && (*nIt != pStateBranch->markers().end())) *pMarkerId = (OdTrVisGsMarker)(*nIt)->first; if (!nIt || *nIt == pStateBranch->markers().end()) { if (nIt) call_dest(*nIt); return OdTrVisStateMarkerIt(); } #if defined(_MSC_VER) #pragma warning(disable : 4127) // conditional expression is constant #pragma warning(push) #endif if (exsz) it.m_pData[0] = &(*(*nIt)); #if defined(_MSC_VER) #pragma warning(pop) #endif return it; } OdUInt32 OdTrVecStateBranchGsClient::stateBranchIntegerParam(OdTrVisStateBranchPtr pStateBranchIn, OdTrVisStateMarkerPtr pMarker) const { const OdGsStateBranch *pStateBranch = reinterpret_cast(pStateBranchIn); if (pMarker) { const OdGsMarkerSet::value_type *pValue = reinterpret_cast(pMarker); if (!pValue->second.isNull() && (pStateBranch->type() == OdGsStateBranch::kHighlightingBranch)) return static_cast(pValue->second.get())->value(); return 0; } return pStateBranch->dataAsInt(); } const OdGeMatrix3d &OdTrVecStateBranchGsClient::stateBranchMatrixParam(OdTrVisStateBranchPtr pStateBranchIn, OdTrVisStateMarkerPtr pMarker) const { const OdGsStateBranch *pStateBranch = reinterpret_cast(pStateBranchIn); if (pMarker) { const OdGsMarkerSet::value_type *pValue = reinterpret_cast(pMarker); if (!pValue->second.isNull() && (pStateBranch->type() == OdGsStateBranch::kTransformationBranch)) return static_cast(pValue->second.get())->value(); return OdGeMatrix3d::kIdentity; } return pStateBranch->dataAsMatrix(); } class OdTrVisGsBranchMarkersAccessor : public OdTrRndMarkersAccessor { protected: const OdGsMarkerSet* m_pSet; OdTrVisGsBranchMarkersAccessor *m_pNext; mutable OdGsSimpleParam const *m_pParam; public: OdTrVisGsBranchMarkersAccessor( const OdGsMarkerSet* pSet ) : m_pSet( pSet ), m_pNext(nullptr), m_pParam(nullptr) {} ~OdTrVisGsBranchMarkersAccessor() { } inline void setNext(OdTrVisGsBranchMarkersAccessor *pNext) { m_pNext = pNext; } inline OdTrVisGsBranchMarkersAccessor *getNext() const { return m_pNext; } inline void setMarkersSet(const OdGsMarkerSet *pSet) { m_pSet = pSet; } const OdGsMarkerSet *markersSet() const { return m_pSet; } bool empty() const override { if( !m_pSet ) return true; return m_pSet->empty(); } bool hasMarker( OdGsMarker marker ) const override { if( !m_pSet ) return false; auto it = m_pSet->find(marker); if (it != m_pSet->end()) { m_pParam = it->second.get(); return true; } else m_pParam = nullptr; return false; } OdUInt32 integerParam() const override { if (m_pParam) return static_cast(m_pParam)->value(); return 0; } const OdGeMatrix3d &matrixParam() const override { if (m_pParam) return static_cast(m_pParam)->value(); return OdGeMatrix3d::kIdentity; } bool interval( OdGsMarker& minMarker, OdGsMarker& maxMarker ) const override { if( !m_pSet || m_pSet->empty() ) return false; minMarker = m_pSet->begin()->first; maxMarker = m_pSet->rbegin()->first; return true; } }; OdTrVecStateBranchGsClient::~OdTrVecStateBranchGsClient() { while (m_pFreedAccessors) { OdTrVisGsBranchMarkersAccessor *pAccessor = m_pFreedAccessors; m_pFreedAccessors = pAccessor->getNext(); delete pAccessor; } ODA_ASSERT(!m_pUsedAccessors); } OdTrRndMarkersAccessor* OdTrVecStateBranchGsClient::stateBranchMarkers( OdTrVisStateBranchPtr pHlBranchIn ) const { const OdGsStateBranch* pHlBranch = reinterpret_cast( pHlBranchIn ); if( !pHlBranch ) return NULL; OdTrVisGsBranchMarkersAccessor *pAccessor; if (m_pFreedAccessors) pAccessor = m_pFreedAccessors, m_pFreedAccessors = pAccessor->getNext(), pAccessor->setMarkersSet(&pHlBranch->markers()); else pAccessor = new OdTrVisGsBranchMarkersAccessor(&pHlBranch->markers()); pAccessor->setNext(m_pUsedAccessors); m_pUsedAccessors = pAccessor; return pAccessor; } void OdTrVecStateBranchGsClient::releaseMarkersAccessor( OdTrRndMarkersAccessor* pAccessor ) const { OdTrVisGsBranchMarkersAccessor* pA = static_cast( pAccessor ); OdTrVisGsBranchMarkersAccessor *pPrevAccessor = NULL, *pCurAccessor = m_pUsedAccessors; while (pCurAccessor) { if (pCurAccessor == pA) break; pPrevAccessor = pCurAccessor; pCurAccessor = pCurAccessor->getNext(); } ODA_ASSERT(pCurAccessor != NULL); if (pCurAccessor) { if (pPrevAccessor) pPrevAccessor->setNext(pCurAccessor->getNext()); else m_pUsedAccessors = pCurAccessor->getNext(); pCurAccessor->setNext(m_pFreedAccessors); m_pFreedAccessors = pCurAccessor; } else delete pA; } OdTrRndStateBranchClientPtr OdTrVecStateBranchGsClient::createObject() { return OdRxObjectImpl::createObject(); } // OdTrVecLocalRenditionGsClient OdTrRndLocalContextPtr OdTrVecLocalRenditionGsClient::createLocalContext(OdTrVisRenderClient */*pDevice*/) { return OdTrRndLocalContextPtr(); } OdTrRndStateBranchClientPtr OdTrVecLocalRenditionGsClient::stateBranchClient() { if (m_pStateBranchClient.isNull()) m_pStateBranchClient = OdTrVecStateBranchGsClient::createObject(); return m_pStateBranchClient; } OdTrVisSharingProviderClientPtr OdTrVecLocalRenditionGsClient::createSharingProvider() { return OdTrVecLocalSharingProvider::createObject(renderModule()); } bool OdTrVecLocalRenditionGsClient::generateLinetypeTexture(OdPs::LineType ltpId, OdUInt8Array& outPixels, OdUInt8 forePixVal) const { outPixels = ::odgiGetPsLinetypesManager().rasterizeLinetype(ltpId, 2, forePixVal); return true; } bool OdTrVecLocalRenditionGsClient::generateFilltypeTexture(OdPs::FillStyle fsId, OdUInt8Array& outPixels, OdUInt32 dimX, OdUInt32 dimY, OdUInt8 forePixVal) const { outPixels = ::odgiGetPsFillstylesManager().rasterizeFillstyle(fsId, 0, 0, dimX, dimY, forePixVal); return true; } OdTrRndLocalRenditionClientPtr OdTrVecLocalRenditionGsClient::createObject(OdTrRndRenderModule *pRenderModule) { OdSmartPtr pLRC = OdRxObjectImpl::createObject(); pLRC->m_pRenderModule = pRenderModule; return pLRC; } //