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

233 lines
8.3 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"
//######################################################################################################################
void sttraverseIFCRootEntity(A3DBIMRoot* pRoot, _TiXmlElement* element)
{
A3DBIMRootData sData;
A3D_INITIALIZE_DATA(A3DBIMRootData, sData);
A3DStatus iRet = A3DBIMRootGet(pRoot, &sData);
_TiXmlElement* root = new _TiXmlElement(sData.m_pcIfcClassName ? sData.m_pcIfcClassName : "Element");
element->LinkEndChild(root);
if (iRet == A3D_SUCCESS)
{
if (sData.m_pcGUID)
root->SetAttribute("global_id", sData.m_pcGUID);
else
root->SetAttribute("global_id", "error");
if (sData.m_pcName)
root->SetAttribute("name", sData.m_pcName);
if (sData.m_pcDescription)
root->SetAttribute("description", sData.m_pcDescription);
if (sData.m_pEntityReference)
{
_TiXmlElement* entity = new _TiXmlElement("Corresponding_A3D");
root->LinkEndChild(entity);
traverseEntityReference(sData.m_pEntityReference, entity);
}
else
root->SetAttribute("Corresponding_A3D", "error");
iRet = A3DBIMRootGet(nullptr, &sData);
}
}
//**********************************************************************************************************************
void dumpRelationship(A3DBIMRoot* pRelating, A3DUns32 uiRelatedElementSize, A3DBIMRoot** ppRelatedElements, _TiXmlElement* rel)
{
if (rel == nullptr)
return;
_TiXmlElement* relating = new _TiXmlElement("Relating");
rel->LinkEndChild(relating);
if (pRelating)
sttraverseIFCRootEntity(pRelating, relating);
else
relating->SetAttribute("relating", "error");
_TiXmlElement* related = new _TiXmlElement("Related");
rel->LinkEndChild(related);
char attribName[2048];
if (uiRelatedElementSize > 0)
{
for (A3DUns32 uj = 0; uj < uiRelatedElementSize; ++uj)
{
if (ppRelatedElements[uj] == nullptr)
{
sprintf(attribName, "related_%d", uj);
related->SetAttribute(attribName, "error");
continue;
}
sttraverseIFCRootEntity(ppRelatedElements[uj], related);
}
}
else
{
related->SetAttribute("related", "error");
}
}
//######################################################################################################################
int dumpRelationships(const A3DBIMData* pBimData, _TiXmlElement* model)
{
if (pBimData == nullptr || model == nullptr)
return A3D_SUCCESS;
char attribName[2048];
A3DUns32 ui;
A3DBIMDataData sBIMData;
A3D_INITIALIZE_DATA(A3DBIMDataData, sBIMData);
CHECK_RET(A3DBIMDataGet(pBimData, &sBIMData));
_TiXmlElement* bim = new _TiXmlElement("BIM");
model->LinkEndChild(bim);
for (ui = 0; ui < sBIMData.m_uiRelationshipSize; ++ui)
{
A3DEEntityType eType = kA3DTypeUnknown;
if( A3DEntityGetType(sBIMData.m_ppRelationships[ui], &eType) != A3D_SUCCESS)
{
bim->SetAttribute("Ifc_relationship", "error: unknown type");
continue;
}
if (eType == kA3DTypeBIMRelContainedInSpatialStructure)
{
A3DBIMRelContainedInSpatialStructureData sRelData;
A3D_INITIALIZE_DATA(A3DBIMRelContainedInSpatialStructureData, sRelData);
if (A3DBIMRelContainedInSpatialStructureGet(sBIMData.m_ppRelationships[ui], &sRelData) == A3D_SUCCESS)
{
_TiXmlElement* rel = new _TiXmlElement("A3DBIMRelContainedInSpatialStructure");
bim->LinkEndChild(rel);
dumpRelationship(sRelData.m_pRelating, sRelData.m_uiRelatedElementSize, sRelData.m_ppRelatedElements, rel);
A3DBIMRelContainedInSpatialStructureGet(nullptr, &sRelData);
}
else
{
sprintf(attribName, "kA3DTypeBIMRelContainedInSpatialStructure_%d", ui);
bim->SetAttribute(attribName, "error");
}
}
else if (eType == kA3DTypeBIMRelAggregates)
{
A3DBIMRelAggregatesData sRelData;
A3D_INITIALIZE_DATA(A3DBIMRelAggregatesData, sRelData);
if (A3DBIMRelAggregatesGet(sBIMData.m_ppRelationships[ui], &sRelData) == A3D_SUCCESS)
{
_TiXmlElement* rel = new _TiXmlElement("A3DBIMRelAggregates");
bim->LinkEndChild(rel);
dumpRelationship(sRelData.m_pRelating, sRelData.m_uiRelatedElementSize, sRelData.m_ppRelatedElements, rel);
A3DBIMRelAggregatesGet(nullptr, &sRelData);
}
else
{
sprintf(attribName, "kA3DTypeBIMRelAggregates_%d", ui);
bim->SetAttribute(attribName, "error");
}
}
else if (eType == kA3DTypeBIMRelFillsElement)
{
A3DBIMRelFillsElementData sRelData;
A3D_INITIALIZE_DATA(A3DBIMRelFillsElementData, sRelData);
if (A3DBIMRelFillsElementGet(sBIMData.m_ppRelationships[ui], &sRelData) == A3D_SUCCESS)
{
_TiXmlElement* rel = new _TiXmlElement("A3DBIMRelFillsElement");
bim->LinkEndChild(rel);
dumpRelationship(sRelData.m_pRelating, sRelData.m_uiRelatedElementSize, sRelData.m_ppRelatedElements, rel);
A3DBIMRelFillsElementGet(nullptr, &sRelData);
}
else
{
sprintf(attribName, "kA3DTypeBIMRelFillsElement_%d", ui);
bim->SetAttribute(attribName, "error");
}
}
else if (eType == kA3DTypeBIMRelVoidsElement)
{
A3DBIMRelVoidsElementData sRelData;
A3D_INITIALIZE_DATA(A3DBIMRelVoidsElementData, sRelData);
if (A3DBIMRelVoidsElementGet(sBIMData.m_ppRelationships[ui], &sRelData) == A3D_SUCCESS)
{
_TiXmlElement* rel = new _TiXmlElement("A3DBIMRelVoidsElement");
bim->LinkEndChild(rel);
dumpRelationship(sRelData.m_pRelating, sRelData.m_uiRelatedElementSize, sRelData.m_ppRelatedElements, rel);
A3DBIMRelVoidsElementGet(nullptr, &sRelData);
}
else
{
sprintf(attribName, "kA3DTypeBIMRelVoidsElement_%d", ui);
bim->SetAttribute(attribName, "error");
}
}
else if (eType == kA3DTypeBIMRelSpaceBoundary)
{
A3DBIMRelSpaceBoundaryData sRelData;
A3D_INITIALIZE_DATA(A3DBIMRelSpaceBoundaryData, sRelData);
if (A3DBIMRelSpaceBoundaryGet(sBIMData.m_ppRelationships[ui], &sRelData) == A3D_SUCCESS)
{
_TiXmlElement* rel = new _TiXmlElement("A3DBIMRelSpaceBoundary");
bim->LinkEndChild(rel);
dumpRelationship(sRelData.m_pRelating, sRelData.m_uiRelatedElementSize, sRelData.m_ppRelatedElements, rel);
A3DBIMRelSpaceBoundaryGet(nullptr, &sRelData);
}
else
{
sprintf(attribName, "kA3DTypeBIMRelSpaceBoundary_%d", ui);
bim->SetAttribute(attribName, "error");
}
}
else if (eType == kA3DTypeBIMRelConnectsPathElements)
{
A3DBIMRelConnectsPathElementsData sRelData;
A3D_INITIALIZE_DATA(A3DBIMRelConnectsPathElementsData, sRelData);
if (A3DBIMRelConnectsPathElementsGet(sBIMData.m_ppRelationships[ui], &sRelData) == A3D_SUCCESS)
{
_TiXmlElement* rel = new _TiXmlElement("A3DBIMRelConnectsPathElementsData");
bim->LinkEndChild(rel);
dumpRelationship(sRelData.m_pRelating, sRelData.m_uiRelatedElementSize, sRelData.m_ppRelatedElements, rel);
A3DBIMRelConnectsPathElementsGet(nullptr, &sRelData);
}
else
{
sprintf(attribName, "kA3DTypeBIMRelConnectsPathElements_%d", ui);
bim->SetAttribute(attribName, "error");
}
}
else if (eType == kA3DTypeBIMRelAssignsToGroup)
{
A3DBIMRelAssignsToGroupData sRelData;
A3D_INITIALIZE_DATA(A3DBIMRelAssignsToGroupData, sRelData);
if (A3DBIMRelAssignsToGroupGet(sBIMData.m_ppRelationships[ui], &sRelData) == A3D_SUCCESS)
{
_TiXmlElement* rel = new _TiXmlElement("A3DBIMRelAssignsToGroupData");
bim->LinkEndChild(rel);
dumpRelationship(sRelData.m_pRelating, sRelData.m_uiRelatedElementSize, sRelData.m_ppRelatedElements, rel);
A3DBIMRelAssignsToGroupGet(nullptr, &sRelData);
}
else
{
sprintf(attribName, "kA3DTypeBIMRelAssignsToGroup_%d", ui);
bim->SetAttribute(attribName, "error");
}
}
else
{
bim->SetAttribute("Ifc_relationship", "error: new type");
bim->SetAttribute(attribName, "error");
}
}
CHECK_RET(A3DBIMDataGet(nullptr, &sBIMData));
return A3D_SUCCESS;
}