506 lines
16 KiB
C++
506 lines
16 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"
|
|
|
|
#include <memory>
|
|
|
|
//######################################################################################################################
|
|
A3DStatus traverseCSys(const A3DRiCoordinateSystem* pCSys, _TiXmlElement* setting)
|
|
{
|
|
A3DRiCoordinateSystemData sData;
|
|
A3D_INITIALIZE_DATA(A3DRiCoordinateSystemData, sData);
|
|
|
|
_TiXmlElement* csys = new _TiXmlElement("A3DRiCoordinateSystemData");
|
|
setAttributePRC2XMLID(pCSys, csys);
|
|
traverseSource(pCSys, csys);
|
|
|
|
A3DStatus iRet = A3DRiCoordinateSystemGet(pCSys, &sData);
|
|
if(iRet == A3D_SUCCESS)
|
|
{
|
|
iRet = traverseTransformation(sData.m_pTransformation, csys);
|
|
A3DRiCoordinateSystemGet(NULL, &sData);
|
|
}
|
|
else
|
|
{
|
|
csys->SetAttribute("error", A3DMiscGetErrorMsg(iRet));
|
|
}
|
|
|
|
setting->LinkEndChild(csys);
|
|
return iRet;
|
|
}
|
|
|
|
//######################################################################################################################
|
|
A3DStatus traverseRepItemContent(const A3DRiRepresentationItem* pRi, _TiXmlElement* setting)
|
|
{
|
|
A3DStatus iRet = A3D_SUCCESS;
|
|
A3DRiRepresentationItemData sData;
|
|
A3D_INITIALIZE_DATA(A3DRiRepresentationItemData, sData);
|
|
|
|
iRet = A3DRiRepresentationItemGet(pRi, &sData);
|
|
if(iRet == A3D_SUCCESS)
|
|
{
|
|
std::unique_ptr<_TiXmlElement> repitemdata(new _TiXmlElement("A3DRiRepresentationItemData"));
|
|
|
|
if(sData.m_pCoordinateSystem)
|
|
traverseCSys(sData.m_pCoordinateSystem, repitemdata.get());
|
|
|
|
if(sData.m_pTessBase)
|
|
traverseTessBase(sData.m_pTessBase, repitemdata.get());
|
|
|
|
if(sData.m_pCoordinateSystem || sData.m_pTessBase)
|
|
setting->LinkEndChild(repitemdata.release());
|
|
|
|
A3DRiRepresentationItemGet(NULL, &sData);
|
|
}
|
|
|
|
return A3D_SUCCESS;
|
|
}
|
|
|
|
//######################################################################################################################
|
|
static A3DStatus traverseBrepModel(const A3DRiBrepModel* pBrepModel, _TiXmlElement* setting)
|
|
{
|
|
A3DRiBrepModelData sData;
|
|
A3D_INITIALIZE_DATA(A3DRiBrepModelData, sData);
|
|
|
|
_TiXmlElement* brep = new _TiXmlElement("A3DRiBrepModelData");
|
|
setAttributePRC2XMLID(pBrepModel, brep);
|
|
traverseSource(pBrepModel, brep);
|
|
traverseRepItemContent(pBrepModel, brep);
|
|
traverseMaterialProperties(pBrepModel, brep);
|
|
|
|
_TiXmlElement* physicalprops = new _TiXmlElement("A3DPhysicalPropertiesData");
|
|
|
|
A3DVector3dData psScale;
|
|
A3D_INITIALIZE_DATA(A3DVector3dData, psScale);
|
|
psScale.m_dX = 1;
|
|
psScale.m_dY = 1;
|
|
psScale.m_dZ = 1;
|
|
A3DPhysicalPropertiesData physicalPropertiesData;
|
|
A3D_INITIALIZE_A3DPhysicalPropertiesData(physicalPropertiesData);
|
|
A3DStatus iRet = A3DComputePhysicalProperties(pBrepModel, &psScale, &physicalPropertiesData);
|
|
|
|
if (iRet == A3D_SUCCESS)
|
|
{
|
|
physicalprops->SetAttribute("m_bVolumecomputed", physicalPropertiesData.m_bVolumeComputed);
|
|
physicalprops->SetDoubleAttribute("m_dSurface", (double)physicalPropertiesData.m_dSurface);
|
|
physicalprops->SetDoubleAttribute("m_dVolume", (double)physicalPropertiesData.m_dVolume);
|
|
|
|
physicalprops->SetDoubleAttribute("m_sGravityCenter.m_dX", (double)physicalPropertiesData.m_sGravityCenter.m_dX);
|
|
physicalprops->SetDoubleAttribute("m_sGravityCenter.m_dY", (double)physicalPropertiesData.m_sGravityCenter.m_dY);
|
|
physicalprops->SetDoubleAttribute("m_sGravityCenter.m_dZ", (double)physicalPropertiesData.m_sGravityCenter.m_dZ);
|
|
}
|
|
else
|
|
{
|
|
physicalprops->SetAttribute("error", A3DMiscGetErrorMsg(iRet));
|
|
}
|
|
|
|
brep->LinkEndChild(physicalprops);
|
|
iRet = A3DRiBrepModelGet(pBrepModel, &sData);
|
|
if(iRet == A3D_SUCCESS)
|
|
{
|
|
traverseBrepData(sData.m_pBrepData, brep);
|
|
A3DRiBrepModelGet(NULL, &sData);
|
|
}
|
|
|
|
setting->LinkEndChild(brep);
|
|
return iRet;
|
|
}
|
|
|
|
//######################################################################################################################
|
|
static A3DStatus traversePolyBrepModel(const A3DRiPolyBrepModel* pPolyBrepModel, _TiXmlElement* setting)
|
|
{
|
|
A3DRiPolyBrepModelData sData;
|
|
A3D_INITIALIZE_DATA(A3DRiPolyBrepModelData, sData);
|
|
|
|
_TiXmlElement* polybrep = new _TiXmlElement("A3DRiPolyBrepModelData");
|
|
setAttributePRC2XMLID(pPolyBrepModel, polybrep);
|
|
traverseSource(pPolyBrepModel, polybrep);
|
|
traverseRepItemContent(pPolyBrepModel, polybrep);
|
|
traverseMaterialProperties(pPolyBrepModel, polybrep);
|
|
|
|
A3DPhysicalPropertiesData physicalPropertiesData;
|
|
A3D_INITIALIZE_DATA(A3DPhysicalPropertiesData, physicalPropertiesData);
|
|
A3DVector3dData psScale;
|
|
A3D_INITIALIZE_DATA(A3DVector3dData, psScale);
|
|
psScale.m_dX = 1;
|
|
psScale.m_dY = 1;
|
|
psScale.m_dZ = 1;
|
|
A3DStatus iRet = A3DComputePolyBrepPhysicalProperties(pPolyBrepModel, &psScale, &physicalPropertiesData);
|
|
|
|
_TiXmlElement* physicalprops = new _TiXmlElement("A3DPhysicalPropertiesData");
|
|
physicalprops->SetAttribute("m_bVolumecomputed", physicalPropertiesData.m_bVolumeComputed);
|
|
physicalprops->SetDoubleAttribute("m_dSurface", (double)physicalPropertiesData.m_dSurface);
|
|
physicalprops->SetDoubleAttribute("m_dVolume", (double)physicalPropertiesData.m_dVolume);
|
|
|
|
physicalprops->SetDoubleAttribute("m_sGravityCenter.m_dX",(double) physicalPropertiesData.m_sGravityCenter.m_dX);
|
|
physicalprops->SetDoubleAttribute("m_sGravityCenter.m_dY", (double)physicalPropertiesData.m_sGravityCenter.m_dY);
|
|
physicalprops->SetDoubleAttribute("m_sGravityCenter.m_dZ",(double) physicalPropertiesData.m_sGravityCenter.m_dZ);
|
|
|
|
polybrep->LinkEndChild(physicalprops);
|
|
|
|
iRet = A3DRiPolyBrepModelGet(pPolyBrepModel, &sData);
|
|
if(iRet == A3D_SUCCESS)
|
|
{
|
|
polybrep->SetAttribute("m_bIsClosed", (int) sData.m_bIsClosed);
|
|
A3DRiPolyBrepModelGet(NULL, &sData);
|
|
}
|
|
|
|
setting->LinkEndChild(polybrep);
|
|
return iRet;
|
|
}
|
|
|
|
//######################################################################################################################
|
|
static A3DStatus traversePolyWire(const A3DRiPolyWire* pPolyWire, _TiXmlElement* setting)
|
|
{
|
|
_TiXmlElement* pPolyWireElement = new _TiXmlElement("A3DRiPolyWireData");
|
|
|
|
setAttributePRC2XMLID(pPolyWire, pPolyWireElement);
|
|
traverseSource(pPolyWire, pPolyWireElement);
|
|
traverseRepItemContent(pPolyWire, pPolyWireElement);
|
|
traverseMaterialProperties(pPolyWire, pPolyWireElement);
|
|
|
|
setting->LinkEndChild(pPolyWireElement);
|
|
|
|
return A3D_SUCCESS;
|
|
}
|
|
|
|
//######################################################################################################################
|
|
static A3DStatus traverseRICurve(const A3DRiCurve* pRICrv, _TiXmlElement* setting)
|
|
{
|
|
A3DRiCurveData sData;
|
|
A3D_INITIALIZE_DATA(A3DRiCurveData, sData);
|
|
|
|
_TiXmlElement* ricrv = new _TiXmlElement("A3DRiCurveData");
|
|
setAttributePRC2XMLID(pRICrv, ricrv);
|
|
traverseSource(pRICrv, ricrv);
|
|
traverseRepItemContent(pRICrv, ricrv);
|
|
traverseMaterialProperties(pRICrv, ricrv);
|
|
|
|
A3DStatus iRet = A3DRiCurveGet(pRICrv, &sData);
|
|
if(iRet == A3D_SUCCESS)
|
|
{
|
|
traverseSingleWireBody(sData.m_pBody, ricrv);
|
|
A3DRiCurveGet(NULL, &sData);
|
|
}
|
|
|
|
setting->LinkEndChild(ricrv);
|
|
return iRet;
|
|
}
|
|
|
|
//######################################################################################################################
|
|
static A3DStatus traverseRIPlane(const A3DRiPlane* pRIPlane, _TiXmlElement* setting)
|
|
{
|
|
A3DRiPlaneData sData;
|
|
A3D_INITIALIZE_DATA(A3DRiPlaneData, sData);
|
|
|
|
_TiXmlElement* riplane = new _TiXmlElement("A3DRiPlaneData");
|
|
setAttributePRC2XMLID(pRIPlane, riplane);
|
|
traverseSource(pRIPlane, riplane);
|
|
traverseRepItemContent(pRIPlane, riplane);
|
|
traverseMaterialProperties(pRIPlane, riplane);
|
|
|
|
A3DStatus iRet = A3DRiPlaneGet(pRIPlane, &sData);
|
|
if(iRet == A3D_SUCCESS)
|
|
{
|
|
traverseBrepData(sData.m_pBrepData, riplane);
|
|
A3DRiPlaneGet(NULL, &sData);
|
|
}
|
|
|
|
setting->LinkEndChild(riplane);
|
|
return iRet;
|
|
}
|
|
|
|
//######################################################################################################################
|
|
static A3DStatus traverseDirection(const A3DRiDirection* pDirection, _TiXmlElement* setting)
|
|
{
|
|
A3DRiDirectionData sData;
|
|
A3D_INITIALIZE_DATA(A3DRiDirectionData, sData);
|
|
|
|
_TiXmlElement* dir = new _TiXmlElement("A3DRiDirectionData");
|
|
setAttributePRC2XMLID(pDirection, dir);
|
|
traverseSource(pDirection, dir);
|
|
traverseRepItemContent(pDirection, dir);
|
|
|
|
A3DStatus iRet = A3DRiDirectionGet(pDirection, &sData);
|
|
if(iRet == A3D_SUCCESS)
|
|
{
|
|
traversePoint("m_sOrigin" , sData.m_sOrigin , dir);
|
|
traversePoint("m_sDirection", sData.m_sDirection, dir);
|
|
A3DRiDirectionGet(NULL, &sData);
|
|
}
|
|
else
|
|
{
|
|
dir->SetAttribute("error", A3DMiscGetErrorMsg(iRet));
|
|
}
|
|
|
|
setting->LinkEndChild(dir);
|
|
return iRet;
|
|
}
|
|
|
|
//######################################################################################################################
|
|
static A3DStatus traversePointSet(const A3DRiPointSet* pPointSet, _TiXmlElement* setting)
|
|
{
|
|
A3DRiPointSetData sData;
|
|
A3D_INITIALIZE_DATA(A3DRiPointSetData, sData);
|
|
|
|
_TiXmlElement* pointset = new _TiXmlElement("A3DRiPointSetData");
|
|
setAttributePRC2XMLID(pPointSet, pointset);
|
|
traverseSource(pPointSet, pointset);
|
|
traverseRepItemContent(pPointSet, pointset);
|
|
traverseMaterialProperties(pPointSet, pointset);
|
|
|
|
A3DStatus iRet = A3DRiPointSetGet(pPointSet, &sData);
|
|
if(iRet == A3D_SUCCESS)
|
|
{
|
|
for(A3DUns32 ui = 0; ui < sData.m_uiSize; ++ui)
|
|
traversePoint("m_pPts", sData.m_pPts[ui], pointset);
|
|
A3DRiPointSetGet(NULL, &sData);
|
|
}
|
|
else
|
|
{
|
|
pointset->SetAttribute("error", A3DMiscGetErrorMsg(iRet));
|
|
}
|
|
|
|
setting->LinkEndChild(pointset);
|
|
return iRet;
|
|
}
|
|
|
|
//######################################################################################################################
|
|
static A3DStatus traverseSet(const A3DRiSet* pSet, _TiXmlElement* setting)
|
|
{
|
|
A3DStatus iRet = A3D_SUCCESS;
|
|
A3DRiSetData sData;
|
|
A3D_INITIALIZE_DATA(A3DRiSetData, sData);
|
|
|
|
_TiXmlElement* set = new _TiXmlElement("A3DRiSetData");
|
|
setAttributePRC2XMLID(pSet, set);
|
|
traverseSource(pSet, set);
|
|
traverseRepItemContent(pSet, set);
|
|
traverseMaterialProperties(pSet, set);
|
|
|
|
iRet = A3DRiSetGet(pSet, &sData);
|
|
if(iRet == A3D_SUCCESS)
|
|
{
|
|
for(A3DUns32 ui = 0; ui < sData.m_uiRepItemsSize; ++ui)
|
|
iRet = traverseRepItem(sData.m_ppRepItems[ui], set);
|
|
|
|
A3DRiSetGet(NULL, &sData);
|
|
}
|
|
else
|
|
{
|
|
set->SetAttribute("error", A3DMiscGetErrorMsg(iRet));
|
|
}
|
|
|
|
setting->LinkEndChild(set);
|
|
return iRet;
|
|
}
|
|
|
|
//######################################################################################################################
|
|
A3DStatus traverseDrawingBlock(const A3DDrawingBlock *pDrwBlock, _TiXmlElement* setting)
|
|
{
|
|
A3DStatus iRet = A3D_SUCCESS;
|
|
|
|
A3DDrawingBlockBasicData sDrwBlockData;
|
|
A3D_INITIALIZE_DATA(A3DDrawingBlockBasicData, sDrwBlockData);
|
|
|
|
CHECK_RET( A3DDrawingBlockBasicGet( (A3DDrawingBlockBasic const*) pDrwBlock, &sDrwBlockData));
|
|
|
|
_TiXmlElement* drwBlock = new _TiXmlElement("A3DDrawingBlockData");
|
|
setAttributePRC2XMLID(pDrwBlock, drwBlock);
|
|
traverseSource(pDrwBlock, drwBlock);
|
|
|
|
drwBlock->SetAttribute("Nb_Entities", sDrwBlockData.m_uiDrwEntitiesSize);
|
|
drwBlock->SetAttribute("Nb_Markups", sDrwBlockData.m_uiMarkupsSize);
|
|
drwBlock->SetAttribute("Nb_SubBlocks", sDrwBlockData.m_uiDrwBlocksSize);
|
|
|
|
for (A3DUns32 ui = 0; ui < sDrwBlockData.m_uiMarkupsSize; ++ui)
|
|
{
|
|
traverseMarkup(sDrwBlockData.m_ppMarkups[ui], drwBlock);
|
|
}
|
|
|
|
setting->LinkEndChild(drwBlock);
|
|
|
|
return iRet;
|
|
}
|
|
|
|
//######################################################################################################################
|
|
A3DStatus traverseDrawingView(const A3DDrawingView *pDrwView, _TiXmlElement* setting)
|
|
{
|
|
|
|
A3DDrawingViewData sDrwViewData;
|
|
A3D_INITIALIZE_DATA(A3DDrawingViewData, sDrwViewData);
|
|
|
|
|
|
_TiXmlElement* drwView = new _TiXmlElement("A3DDrawingViewData");
|
|
|
|
// Get the type of the drawing view
|
|
A3DStatus iRet = A3D_SUCCESS;
|
|
|
|
iRet = A3DDrawingViewGet(pDrwView, &sDrwViewData);
|
|
|
|
A3DEDrawingViewType eDrwType = sDrwViewData.m_eType;
|
|
|
|
switch(eDrwType)
|
|
{
|
|
case kA3DDrawingViewTypeIso:
|
|
drwView->SetAttribute("ISO_view",1);
|
|
case kA3DDrawingViewTypeTop:
|
|
drwView->SetAttribute("Top_view",1);
|
|
case kA3DDrawingViewTypeBottom:
|
|
drwView->SetAttribute("Bottom_view",1);
|
|
case kA3DDrawingViewTypeLeft:
|
|
drwView->SetAttribute("Left_view",1);
|
|
case kA3DDrawingViewTypeRight:
|
|
drwView->SetAttribute("Right_view",1);
|
|
case kA3DDrawingViewTypeFront:
|
|
drwView->SetAttribute("Front_view",1);
|
|
case kA3DDrawingViewTypeBack:
|
|
drwView->SetAttribute("Back_view",1);
|
|
case kA3DDrawingViewTypeBackground:
|
|
drwView->SetAttribute("Background_view",1);
|
|
case kA3DDrawingViewTypeWorking:
|
|
drwView->SetAttribute("Working_view",1);
|
|
case kA3DDrawingViewTypeProjected:
|
|
drwView->SetAttribute("Projected_view",1);
|
|
case kA3DDrawingViewTypeAuxiliary:
|
|
drwView->SetAttribute("Auxiliary_view",1);
|
|
case kA3DDrawingViewTypeSection:
|
|
drwView->SetAttribute("Section_view",1);
|
|
case kA3DDrawingViewTypeDetail :
|
|
drwView->SetAttribute("Detail_view",1);
|
|
default:
|
|
drwView->SetAttribute("Unknown",1);
|
|
break;
|
|
}
|
|
|
|
// get the name of the drawing view
|
|
A3DRootBaseData sData;
|
|
A3D_INITIALIZE_DATA(A3DRootBaseData, sData);
|
|
CHECK_RET(A3DRootBaseGet(pDrwView, &sData));
|
|
|
|
if(sData.m_pcName && sData.m_pcName[0] != '\0')
|
|
drwView->SetAttribute("name", sData.m_pcName);
|
|
A3DRootBaseGet(NULL,&sData);
|
|
|
|
if (sDrwViewData.m_pLocalBlocks)
|
|
{
|
|
traverseDrawingBlock(sDrwViewData.m_pLocalBlocks, drwView);
|
|
}
|
|
|
|
for (A3DUns32 ui = 0; ui < sDrwViewData.m_uiDrwBlocksSize; ++ui)
|
|
{
|
|
traverseDrawingBlock(sDrwViewData.m_ppDrwBlocks[ui], drwView);
|
|
}
|
|
|
|
setting->LinkEndChild(drwView);
|
|
|
|
return iRet;
|
|
}
|
|
|
|
//######################################################################################################################
|
|
A3DStatus traverseDrawingSheet(const A3DDrawingSheet * pDrwSheet, _TiXmlElement* setting)
|
|
{
|
|
A3DStatus iRet = A3D_SUCCESS;
|
|
|
|
A3DDrawingSheetData sDrwSheetData;
|
|
A3D_INITIALIZE_DATA(A3DDrawingSheetData, sDrwSheetData);
|
|
|
|
iRet = A3DDrawingSheetGet(pDrwSheet, &sDrwSheetData);
|
|
|
|
|
|
_TiXmlElement* pSheet = new _TiXmlElement("A3DDrawingSheetdata");
|
|
|
|
for (A3DUns32 ui = 0; ui < sDrwSheetData.m_uiDrwViewsSize; ++ui)
|
|
{
|
|
traverseDrawingView(sDrwSheetData.m_ppDrwViews[ui], pSheet);
|
|
}
|
|
|
|
setting->LinkEndChild(pSheet);
|
|
|
|
return iRet;
|
|
|
|
}
|
|
|
|
//######################################################################################################################
|
|
A3DStatus traverseDrawing(const A3DDrawingModel * pDrawing, _TiXmlElement* setting)
|
|
{
|
|
A3DStatus iRet = A3D_SUCCESS;
|
|
|
|
A3DDrawingModelData sDrwModelData;
|
|
A3D_INITIALIZE_DATA(A3DDrawingModelData, sDrwModelData);
|
|
|
|
A3DRootBaseData sBaseData;
|
|
A3D_INITIALIZE_DATA(A3DRootBaseData, sBaseData);
|
|
|
|
A3DRootBaseGet(pDrawing, &sBaseData);
|
|
|
|
iRet = A3DDrawingModelGet(pDrawing, &sDrwModelData);
|
|
|
|
_TiXmlElement* drawing = new _TiXmlElement("A3DDrawingModeldata");
|
|
|
|
// traverse the drawing sheet
|
|
for (A3DUns32 ui = 0; ui < sDrwModelData.m_uiDrwSheetsSize; ++ui)
|
|
{
|
|
traverseDrawingSheet(sDrwModelData.m_ppDrwSheets[ui], drawing);
|
|
}
|
|
|
|
setting->LinkEndChild(drawing);
|
|
|
|
return iRet;
|
|
}
|
|
|
|
|
|
//######################################################################################################################
|
|
A3DStatus traverseRepItem(const A3DRiRepresentationItem* pRepItem, _TiXmlElement* setting)
|
|
{
|
|
A3DStatus iRet = A3D_SUCCESS;
|
|
A3DEEntityType eType;
|
|
|
|
CHECK_RET(A3DEntityGetType(pRepItem, &eType));
|
|
|
|
switch(eType)
|
|
{
|
|
case kA3DTypeRiSet:
|
|
iRet = traverseSet(pRepItem, setting);
|
|
break;
|
|
case kA3DTypeRiPointSet:
|
|
iRet = traversePointSet(pRepItem, setting);
|
|
break;
|
|
case kA3DTypeRiDirection:
|
|
iRet = traverseDirection(pRepItem, setting);
|
|
break;
|
|
case kA3DTypeRiCurve:
|
|
iRet = traverseRICurve(pRepItem, setting);
|
|
break;
|
|
case kA3DTypeRiCoordinateSystem:
|
|
iRet = traverseCSys(pRepItem, setting);
|
|
break;
|
|
case kA3DTypeRiPlane:
|
|
iRet = traverseRIPlane(pRepItem, setting);
|
|
break;
|
|
case kA3DTypeRiBrepModel:
|
|
iRet = traverseBrepModel(pRepItem, setting);
|
|
break;
|
|
case kA3DTypeRiPolyBrepModel:
|
|
iRet = traversePolyBrepModel(pRepItem, setting);
|
|
break;
|
|
case kA3DTypeRiPolyWire:
|
|
iRet = traversePolyWire(pRepItem, setting);
|
|
break;
|
|
default:
|
|
iRet = A3D_NOT_IMPLEMENTED;
|
|
break;
|
|
}
|
|
return iRet;
|
|
}
|