290 lines
9.4 KiB
C++
290 lines
9.4 KiB
C++
/***********************************************************************************************************************
|
|
*
|
|
* Copyright (c) 2010 - 2025 by Tech Soft 3D, Inc.
|
|
* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret
|
|
* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event
|
|
* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized
|
|
* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the
|
|
* scope and manner of such use.
|
|
*
|
|
***********************************************************************************************************************/
|
|
|
|
#include "../VisitorCascadedAttribute.h"
|
|
#include "../CascadedAttributeConnector.h"
|
|
#include "../VisitorTree.h"
|
|
#include "../VisitorContainer.h"
|
|
#include "../TransfoConnector.h"
|
|
|
|
#include "../callback_opengl.h"
|
|
|
|
A3DVisitorColorMaterials::A3DVisitorColorMaterials(A3DVisitorContainer* psContainer)
|
|
: A3DVisitor("CascadedAttribute", psContainer),
|
|
m_pCurrentRi(NULL)
|
|
{
|
|
}
|
|
|
|
A3DVisitorColorMaterials::~A3DVisitorColorMaterials()
|
|
{
|
|
std::vector<A3DMiscCascadedAttributes*>::iterator itCur = m_apsCascadedAttribute.begin();
|
|
std::vector<A3DMiscCascadedAttributes*>::iterator itEnd = m_apsCascadedAttribute.end();
|
|
for(; itCur < itEnd; ++itCur)
|
|
{
|
|
CALL_A3D_FCTION(A3DMiscCascadedAttributesDelete,(*itCur));
|
|
}
|
|
}
|
|
|
|
A3DStatus A3DVisitorColorMaterials::pushCascadedAttribute(const A3DConnector& sEntity)
|
|
{
|
|
unsigned int uSize = (unsigned int)m_apsCascadedAttribute.size();
|
|
if(!uSize)
|
|
{
|
|
A3DMiscCascadedAttributes* pAttr;
|
|
CALL_A3D_FCTION(A3DMiscCascadedAttributesCreate,(&pAttr));
|
|
m_apsCascadedAttribute.push_back(pAttr);
|
|
uSize++;
|
|
}
|
|
|
|
A3DMiscCascadedAttributes* pAttr;
|
|
CALL_A3D_FCTION(A3DMiscCascadedAttributesCreate,(&pAttr));
|
|
CALL_A3D_FCTION(A3DMiscCascadedAttributesPush,(pAttr, sEntity.GetA3DEntity(), m_apsCascadedAttribute[uSize-1]));
|
|
m_apsCascadedAttribute.push_back(pAttr);
|
|
|
|
return A3D_SUCCESS;
|
|
}
|
|
|
|
|
|
A3DStatus A3DVisitorColorMaterials::popCascadedAttribute(/*const A3DConnector& sEntity*/)
|
|
{
|
|
if(m_apsCascadedAttribute.size() > 0)
|
|
{
|
|
CALL_A3D_FCTION(A3DMiscCascadedAttributesDelete,(m_apsCascadedAttribute[m_apsCascadedAttribute.size() - 1]));
|
|
m_apsCascadedAttribute.pop_back();
|
|
}
|
|
|
|
return A3D_SUCCESS;
|
|
}
|
|
|
|
// Visit Product Occurrence
|
|
A3DStatus A3DVisitorColorMaterials::visitEnter(const A3DProductOccurrenceConnector& sEntity)
|
|
{
|
|
pushCascadedAttribute( (const A3DConnector&) sEntity);
|
|
|
|
return A3D_SUCCESS;
|
|
}
|
|
|
|
A3DStatus A3DVisitorColorMaterials::visitLeave(const A3DProductOccurrenceConnector& /*sEntity*/)
|
|
{
|
|
popCascadedAttribute();
|
|
return A3D_SUCCESS;
|
|
}
|
|
|
|
// Visit PartDefintion
|
|
A3DStatus A3DVisitorColorMaterials::visitEnter(const A3DPartConnector& sEntity)
|
|
{
|
|
pushCascadedAttribute((const A3DConnector& ) sEntity);
|
|
return A3D_SUCCESS;
|
|
}
|
|
|
|
A3DStatus A3DVisitorColorMaterials::visitLeave(const A3DPartConnector& /*sEntity*/)
|
|
{
|
|
popCascadedAttribute();
|
|
return A3D_SUCCESS;
|
|
}
|
|
|
|
// Visit Representation Item
|
|
A3DStatus A3DVisitorColorMaterials::visitEnter(const A3DRiConnector& sRi)
|
|
{
|
|
A3DStatus iRet = A3D_SUCCESS;
|
|
m_pCurrentRi = (A3DRiRepresentationItem*)sRi.GetA3DEntity();
|
|
CHECK_RET(pushCascadedAttribute((const A3DConnector&) sRi));
|
|
CHECK_RET(SetGlobalAttributeOnLeaf(m_apsCascadedAttribute[ m_apsCascadedAttribute.size() - 1]));
|
|
return iRet;
|
|
}
|
|
|
|
A3DStatus A3DVisitorColorMaterials::visitLeave(const A3DRiConnector& /*sRi*/)
|
|
{
|
|
A3DStatus iRet = A3D_SUCCESS;
|
|
m_pCurrentRi = NULL;
|
|
CHECK_RET(popCascadedAttribute());
|
|
return A3D_SUCCESS;
|
|
}
|
|
|
|
// Visit Face Tess Data
|
|
A3DStatus A3DVisitorColorMaterials::visitEnter(const A3DFaceTessDataConnector& sFaceTess)
|
|
{
|
|
A3DStatus iRet = A3D_SUCCESS;
|
|
A3DTessFaceData* pFaceTessData = (A3DTessFaceData*)sFaceTess.GetA3DEntity();
|
|
|
|
if(m_pCurrentRi && !pFaceTessData->m_bIsRGBA && pFaceTessData->m_uiStyleIndexesSize == 1)
|
|
{
|
|
// Push the Face Tess data
|
|
A3DMiscCascadedAttributes* pAttr;
|
|
CALL_A3D_FCTION(A3DMiscCascadedAttributesCreate,(&pAttr));
|
|
CALL_A3D_FCTION(A3DMiscCascadedAttributesPushTessFace,(pAttr,
|
|
m_pCurrentRi,
|
|
(A3DTess3D*)sFaceTess.GetTessDataConnector()->GetA3DEntity(),
|
|
(A3DTessFaceData*)sFaceTess.GetA3DEntity(),
|
|
sFaceTess.GetFaceIndex(),
|
|
m_apsCascadedAttribute[m_apsCascadedAttribute.size()-1]));
|
|
m_apsCascadedAttribute.push_back(pAttr);
|
|
|
|
CHECK_RET(SetGlobalAttributeOnLeaf(m_apsCascadedAttribute[ m_apsCascadedAttribute.size() - 1]));
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////
|
|
// Get Colors / Materials - PLEASE, ADD your sources HERE
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
if(GetstbUseCallbacks())
|
|
{
|
|
A3DVisitorColorMaterials* pVisitorColorAndMaterials = (A3DVisitorColorMaterials *)m_psContainer->GetVisitor()[1];
|
|
ColorMaterialsConnector sColorMaterialConnec(pVisitorColorAndMaterials->GetLastCascadedAttributes());
|
|
pVisitorColorAndMaterials->GetColorMaterialConnector(sColorMaterialConnec, false);
|
|
|
|
if (sColorMaterialConnec.IsShow())
|
|
{
|
|
if(sColorMaterialConnec.IsRGBColor())
|
|
{
|
|
double adRGB[3];
|
|
sColorMaterialConnec.GetRGB(adRGB);
|
|
OpenGL_Material(kA3DDrawMaterialDiffuse, adRGB, 3);
|
|
}
|
|
else
|
|
{
|
|
double adEmisive[4], adDiffuse[4], adAmbient[4], adSpecular[4], dShininess;
|
|
sColorMaterialConnec.GetMaterial(adEmisive, adDiffuse, adAmbient, adSpecular, dShininess );
|
|
OpenGL_Material(kA3DDrawMaterialDiffuse, adDiffuse, 4);
|
|
OpenGL_Material(kA3DDrawMaterialAmbient, adAmbient, 4);
|
|
OpenGL_Material(kA3DDrawMaterialEmission, adEmisive, 4);
|
|
OpenGL_Material(kA3DDrawMaterialSpecular, adSpecular, 4);
|
|
OpenGL_Material(kA3DDrawMaterialShininess, &dShininess, 1);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
return iRet;
|
|
}
|
|
|
|
A3DStatus A3DVisitorColorMaterials::visitLeave(const A3DFaceTessDataConnector& sFaceTess)
|
|
{
|
|
A3DStatus iRet = A3D_SUCCESS;
|
|
A3DTessFaceData* pFaceTessData = (A3DTessFaceData*)sFaceTess.GetA3DEntity();
|
|
if(!pFaceTessData->m_bIsRGBA && pFaceTessData->m_uiStyleIndexesSize == 1)
|
|
{
|
|
CHECK_RET(popCascadedAttribute());
|
|
}
|
|
return A3D_SUCCESS;
|
|
}
|
|
|
|
A3DMiscCascadedAttributes* A3DVisitorColorMaterials::GetLastCascadedAttributes() const
|
|
{
|
|
size_t iSize = m_apsCascadedAttribute.size();
|
|
if(iSize == 0)
|
|
return NULL;
|
|
return m_apsCascadedAttribute[iSize-1];
|
|
}
|
|
|
|
A3DStatus A3DVisitorColorMaterials::GetColorMaterialConnector( ColorMaterialsConnector& rsColorConnector,
|
|
bool bUseInstances /*= false*/ )
|
|
{
|
|
A3DStatus iErr = A3D_SUCCESS;
|
|
size_t iSize = m_apsCascadedAttribute.size();
|
|
if(iSize == 0)
|
|
return A3D_ERROR;
|
|
A3DMiscCascadedAttributes* pCurrent = m_apsCascadedAttribute[iSize-1];
|
|
|
|
if(!bUseInstances)
|
|
{
|
|
A3DMiscEntityReference* pMER = NULL;
|
|
A3DStepEntityRefManager const * pSERM = m_psContainer->GetActiveStepEntityRefManager(NULL);
|
|
if (pSERM)
|
|
{
|
|
pMER = pSERM->m_pStepEntityRef;
|
|
}
|
|
|
|
A3DViewLinkedItemManager const* pVLIM = m_psContainer->GetActiveViewLinkedItemManager(NULL);
|
|
if (pVLIM)
|
|
{
|
|
pMER = pVLIM->m_pMarkupLinkedItem;
|
|
}
|
|
|
|
if (pMER)
|
|
{
|
|
A3DMiscEntityReferenceData sSERData;
|
|
A3D_INITIALIZE_DATA(A3DMiscEntityReferenceData, sSERData);
|
|
iErr = CALL_A3D_FCTION(A3DMiscEntityReferenceGet,(pMER, &sSERData));
|
|
if(iErr == A3D_SUCCESS)
|
|
{
|
|
A3DEEntityType eType;
|
|
CALL_A3D_FCTION(A3DEntityGetType,( pMER, &eType));
|
|
if(eType == kA3DTypeMiscEntityReference || eType==kA3DTypeMiscMarkupLinkedItem)
|
|
{
|
|
A3DMiscReferenceOnTopologyData sTopoRefData;
|
|
A3D_INITIALIZE_DATA(A3DMiscReferenceOnTopologyData,sTopoRefData);
|
|
iErr = CALL_A3D_FCTION(A3DMiscReferenceOnTopologyGet,(pMER, &sTopoRefData));
|
|
if(iErr == A3D_SUCCESS) // topo
|
|
{
|
|
switch(sTopoRefData.m_eTopoItemType)
|
|
{
|
|
case kA3DTypeTopoMultipleVertex:
|
|
case kA3DTypeTopoUniqueVertex:
|
|
case kA3DTypeTopoWireEdge:
|
|
case kA3DTypeTopoEdge:
|
|
case kA3DTypeTopoLoop:
|
|
break;
|
|
case kA3DTypeTopoFace:
|
|
{
|
|
A3DTopoBrepData* pBrepData = sTopoRefData.m_pBrepData;
|
|
A3DTopoBrepDataData sTopoBrepDataData;
|
|
A3D_INITIALIZE_DATA( A3DTopoBrepDataData,sTopoBrepDataData);
|
|
CALL_A3D_FCTION(A3DTopoBrepDataGet,(pBrepData,&sTopoBrepDataData));
|
|
|
|
CALL_A3D_FCTION(A3DTopoBrepDataGet,(NULL,&sTopoBrepDataData));
|
|
|
|
break;
|
|
}
|
|
case kA3DTypeTopoShell:
|
|
{
|
|
break;
|
|
}
|
|
case kA3DTypeTopoConnex:
|
|
{
|
|
break;
|
|
}
|
|
default:
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
else // no topo -> global PO/Part/RI/RIBrepModel
|
|
{
|
|
A3DEEntityType eEType;
|
|
CALL_A3D_FCTION(A3DEntityGetType,( sSERData.m_pEntity, &eEType));
|
|
|
|
//A3DGraphStyleData
|
|
A3DMiscCascadedAttributes* pAttr = NULL;
|
|
CALL_A3D_FCTION(A3DMiscCascadedAttributesCreate,(&pAttr));
|
|
iErr = CALL_A3D_FCTION(A3DMiscCascadedAttributesPush,(pAttr, pMER, pCurrent));
|
|
A3DMiscCascadedAttributesData sCAData;
|
|
A3D_INITIALIZE_DATA(A3DMiscCascadedAttributesData, sCAData);
|
|
iErr = CALL_A3D_FCTION(A3DMiscCascadedAttributesGet,(pAttr, &sCAData));
|
|
rsColorConnector = ColorMaterialsConnector(pAttr);
|
|
}
|
|
|
|
CALL_A3D_FCTION(A3DMiscReferenceOnTopologyGet,(NULL,
|
|
&sTopoRefData));
|
|
}
|
|
CALL_A3D_FCTION(A3DMiscEntityReferenceGet,( NULL, &sSERData));
|
|
}
|
|
}
|
|
else
|
|
rsColorConnector = ColorMaterialsConnector(pCurrent);
|
|
}
|
|
|
|
return A3D_SUCCESS;
|
|
}
|