Files
Hoops_Exchange/exchange/exchangesource/PRC2XML/PRC2XMLRootEntities.cpp
2025-12-15 23:22:33 +08:00

198 lines
7.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 <A3DSDKIncludes.h>
#include "PRC2XML.h"
//######################################################################################################################
A3DStatus traverseAttribute(const A3DMiscAttribute* pAttribute, _TiXmlElement* setting)
{
A3DMiscAttributeData sData;
A3D_INITIALIZE_DATA(A3DMiscAttributeData, sData);
A3DStatus iRet = A3DMiscAttributeGet(pAttribute, &sData);
if(iRet == A3D_SUCCESS)
{
_TiXmlElement* attribute = new _TiXmlElement("A3DMiscAttributeData");
attribute->SetAttribute("m_bTitleIsInt", (int) sData.m_bTitleIsInt);
if(sData.m_bTitleIsInt)
{
A3DUns32 uiVal;
memcpy(&uiVal,sData.m_pcTitle, sizeof(A3DUns32));
attribute->SetAttribute("m_pcTitle", (int)uiVal);
}
else
{
if(sData.m_pcTitle && sData.m_pcTitle[0] != '\0')
attribute->SetAttribute("m_pcTitle", sData.m_pcTitle);
}
for(A3DUns32 ui = 0; ui < sData.m_uiSize; ++ui)
{
_TiXmlElement* single = new _TiXmlElement("m_asSingleAttributesData");
single->SetAttribute("m_bTitleIsInt", (int) sData.m_asSingleAttributesData[ui].m_bTitleIsInt);
if(sData.m_asSingleAttributesData[ui].m_pcTitle == NULL)
single->SetAttribute("m_pcTitle", "NULL");
else if(sData.m_asSingleAttributesData[ui].m_bTitleIsInt)
{
A3DUns32 uiVal;
memcpy(&uiVal,sData.m_asSingleAttributesData[ui].m_pcTitle, sizeof(A3DUns32));
single->SetAttribute("m_pcTitle", (int)uiVal);
}
else
{
if(sData.m_asSingleAttributesData[ui].m_pcTitle && sData.m_asSingleAttributesData[ui].m_pcTitle[0] != '\0')
single->SetAttribute("m_pcTitle", sData.m_asSingleAttributesData[ui].m_pcTitle);
}
A3DInt32 iVal;
switch(sData.m_asSingleAttributesData[ui].m_eType)
{
case kA3DModellerAttributeTypeInt:
memcpy(&iVal, sData.m_asSingleAttributesData[ui].m_pcData, sizeof(A3DInt32));
single->SetAttribute("m_eType", "kA3DModellerAttributeTypeInt");
single->SetAttribute("m_pcData", iVal);
break;
case kA3DModellerAttributeTypeReal:
A3DDouble dVal;
memcpy(&dVal, sData.m_asSingleAttributesData[ui].m_pcData, sizeof(A3DDouble));
single->SetAttribute("m_eType", "kA3DModellerAttributeTypeReal");
setDoubleAttribute(single, "m_pcData", dVal);
if (sData.m_asSingleAttributesData[ui].m_usUnit!= A3D_DEFAULT_NO_UNIT)
single->SetAttribute("m_usUnit", sData.m_asSingleAttributesData[ui].m_usUnit);
break;
case kA3DModellerAttributeTypeTime:
memcpy(&iVal, sData.m_asSingleAttributesData[ui].m_pcData, sizeof(A3DInt32));
single->SetAttribute("m_eType", "kA3DModellerAttributeTypeTime");
single->SetAttribute("m_pcData", iVal);
break;
case kA3DModellerAttributeTypeString:
single->SetAttribute("m_eType", "kA3DModellerAttributeTypeString");
if(sData.m_asSingleAttributesData[ui].m_pcData && sData.m_asSingleAttributesData[ui].m_pcData[0] != '\0')
single->SetAttribute("m_pcData", sData.m_asSingleAttributesData[ui].m_pcData);
break;
default:
break;
}
attribute->LinkEndChild(single);
}
setting->LinkEndChild(attribute);
A3DMiscAttributeGet(NULL, &sData);
}
return A3D_SUCCESS;
}
//######################################################################################################################
A3DStatus traverseGraphics(const A3DGraphics* pGraphics, _TiXmlElement* setting)
{
A3DGraphicsData sData;
A3D_INITIALIZE_DATA(A3DGraphicsData, sData);
A3DStatus iRet = A3DGraphicsGet(pGraphics, &sData);
if(iRet == A3D_SUCCESS)
{
_TiXmlElement* graphics = new _TiXmlElement("A3DGraphicsData");
if(sData.m_uiLayerIndex != A3D_DEFAULT_LAYER)
graphics->SetAttribute("m_uiLayerIndex", (int) sData.m_uiLayerIndex);
if(sData.m_uiStyleIndex != A3D_DEFAULT_STYLE_INDEX)
graphics->SetAttribute("m_uiStyleIndex", (int) sData.m_uiStyleIndex);
graphics->SetAttribute("m_usBehaviour", (int) sData.m_usBehaviour);
CHECK_RET(A3DGraphicsGet(NULL, &sData));
setting->LinkEndChild(graphics);
}
return iRet;
}
//######################################################################################################################
A3DStatus traverseBase(const A3DEntity* pEntity, _TiXmlElement* setting)
{
A3DRootBaseData sData;
A3D_INITIALIZE_DATA(A3DRootBaseData, sData);
A3DStatus iRet = A3DRootBaseGet(pEntity, &sData);
if(iRet == A3D_SUCCESS)
{
_TiXmlElement* base = new _TiXmlElement("A3DRootBaseData");
if(sData.m_pcName && sData.m_pcName[0] != '\0')
base->SetAttribute("m_pcName", sData.m_pcName);
base->SetAttribute("m_uiPersistentId", sData.m_uiPersistentId);
base->SetAttribute("m_uiNonPersistentId", sData.m_uiNonPersistentId);
if (sData.m_pcPersistentId)
base->SetAttribute("m_pcPersistentId", sData.m_pcPersistentId);
for(A3DUns32 ui = 0; ui < sData.m_uiSize; ++ui)
traverseAttribute(sData.m_ppAttributes[ui], base);
A3DBoundingBoxData sBoundingBox;
A3D_INITIALIZE_DATA(A3DBoundingBoxData, sBoundingBox);
iRet = A3DMiscGetBoundingBox(pEntity, &sBoundingBox);
if(iRet == A3D_SUCCESS)
{
if((sBoundingBox.m_sMin.m_dX + sBoundingBox.m_sMin.m_dY + sBoundingBox.m_sMin.m_dZ + sBoundingBox.m_sMax.m_dX + sBoundingBox.m_sMax.m_dY + sBoundingBox.m_sMax.m_dZ) != 0.0)
{
char acBBox[256];
sprintf(acBBox, "Min(%f,%f,%f) Max(%f,%f,%f)", sBoundingBox.m_sMin.m_dX, sBoundingBox.m_sMin.m_dY, sBoundingBox.m_sMin.m_dZ, sBoundingBox.m_sMax.m_dX, sBoundingBox.m_sMax.m_dY, sBoundingBox.m_sMax.m_dZ);
base->SetAttribute("BoundingBox", acBBox);
A3DMiscGetBoundingBox(NULL, &sBoundingBox);
}
}
setting->LinkEndChild(base);
A3DRootBaseGet(NULL, &sData);
}
return A3D_SUCCESS;
}
//######################################################################################################################
A3DStatus traverseBaseWithGraphics(const A3DEntity* pEntity, _TiXmlElement* setting)
{
A3DRootBaseWithGraphicsData sData;
A3D_INITIALIZE_DATA(A3DRootBaseWithGraphicsData, sData);
A3DStatus iRet = A3DRootBaseWithGraphicsGet(pEntity, &sData);
if(iRet == A3D_SUCCESS)
{
_TiXmlElement* basewithgraphics = new _TiXmlElement("A3DRootBaseWithGraphicsData");
traverseBase(pEntity,basewithgraphics);
if(sData.m_pGraphics != NULL)
traverseGraphics(sData.m_pGraphics,basewithgraphics);
setting->LinkEndChild(basewithgraphics);
A3DRootBaseWithGraphicsGet(NULL, &sData);
}
return A3D_SUCCESS;
}
//######################################################################################################################
A3DStatus traverseSource(const A3DEntity* pEntity, _TiXmlElement* setting)
{
if(A3DEntityIsBaseWithGraphicsType(pEntity))
return traverseBaseWithGraphics(pEntity, setting);
else if(A3DEntityIsBaseType(pEntity))
return traverseBase(pEntity, setting);
return A3D_SUCCESS;
}