Files
2025-12-15 23:22:33 +08:00

125 lines
4.5 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.
* DumpFeatureTree.cpp : Defines the entry point for the console application.
*
***********************************************************************************************************************/
#include <hoops_license.h>
#define INITIALIZE_A3D_API
#include "DumpFeatureTree.h"
#define TF_A3DLIBS
#include <math.h>
#include <stdarg.h>
#include <time.h>
#include <vector>
#include "TreeTraverse.h"
#include "VisitorContainer.h"
#include "VisitorTree.h"
#include "HXFeatureTreeReport.h"
//######################################################################################################################
static A3DStatus TraverseModel(const A3DAsmModelFile* pModelFile, const char * pcOutputFile)
{
// Creation of the ModelFile Connector
A3DModelFileConnector sModelFileConnector(pModelFile);
A3DVisitorContainer sCadVisitorContainer(CONNECT_FEATURE);
sCadVisitorContainer.SetTraverseInstance(true);
HXFeatureTreeReport * pReport = new HXFeatureTreeReport(&sCadVisitorContainer);
sCadVisitorContainer.push(pReport);
// Traverse the ModelFile Connector
sModelFileConnector.Traverse(&sCadVisitorContainer);
pReport->SaveFile((const char *)pcOutputFile);
return A3D_SUCCESS;
}
//######################################################################################################################
static MY_CHAR acSrcFileName[_MAX_PATH * 2];
static MY_CHAR acDstFileName[_MAX_PATH * 2 + 4];
static MY_CHAR acLogFileName[_MAX_PATH * 2 + 12];
//######################################################################################################################
#ifdef _MSC_VER
int wmain(A3DInt32 iArgc, wchar_t** ppcArgv)
#else
int main(A3DInt32 iArgc, A3DUTF8Char** ppcArgv)
#endif
{
//
// ### COMMAND LINE ARGUMENTS
//
if (iArgc > 4)
{
MY_PRINTF2("Usage:\n %s [input CAD file] [output XML file] [output LOG file]\n", ppcArgv[0]);
MY_PRINTF(" Default output XML file is [input CAD file].xml\n");
MY_PRINTF(" Default output LOG file is [output XML file]_Log.txt\n\n");
return A3D_ERROR;
}
MY_PRINTF("This sample produces an XML file that is best viewed with a style sheet. \n");
MY_PRINTF("Please copy FeatureHTML.xsl (found in \\samples\\exchange\\exchangesource\\DumpFeatureTree\\) in your XML output directory for better readability. \n");
if (iArgc > 1) MY_STRCPY(acSrcFileName, ppcArgv[1]);
else MY_STRCPY(acSrcFileName, DEFAULT_INPUT_CAD);
if (iArgc > 2) MY_STRCPY(acDstFileName, ppcArgv[2]);
else MY_SPRINTF(acDstFileName, "%s.xml", acSrcFileName);
if (iArgc > 3) MY_STRCPY(acLogFileName, ppcArgv[3]);
else MY_SPRINTF(acLogFileName, "%s_Log.txt", acDstFileName);
GetLogFile(acLogFileName); // Initialize log file
//
// ### INITIALIZE HOOPS EXCHANGE
//
A3DSDKHOOPSExchangeLoader sHoopsExchangeLoader(_T(HOOPS_BINARY_DIRECTORY), HOOPS_LICENSE);
CHECK_RET(sHoopsExchangeLoader.m_eSDKStatus);
CHECK_RET(A3DDllSetCallbacksMemory(CheckMalloc, CheckFree));
CHECK_RET(A3DDllSetCallbacksReport(PrintLogMessage, PrintLogWarning, PrintLogError));
//
// ### PROCESS SAMPLE CODE
//
A3DImport sImport(acSrcFileName); // see A3DSDKInternalConvert.hxx for import and export detailed parameters
sImport.m_sLoadData.m_sGeneral.m_bReadFeature = TRUE;
sImport.m_sLoadData.m_sGeneral.m_bReadHiddenObjects = TRUE;
sImport.m_sLoadData.m_sGeneral.m_bReadConstructionAndReferences = TRUE;
sImport.m_sLoadData.m_sGeneral.m_bReadPmis = FALSE;
A3DStatus iRet = sHoopsExchangeLoader.Import(sImport);
if (iRet != A3D_SUCCESS && iRet != A3D_LOAD_MISSING_COMPONENTS)
CHECK_RET(iRet);
A3DUTF8Char sDstFileNameUTF8[_MAX_PATH];
#ifdef _MSC_VER
A3DMiscUTF16ToUTF8(acDstFileName, sDstFileNameUTF8);
#else
MY_STRCPY(sDstFileNameUTF8, acDstFileName);
#endif
TraverseModel(sHoopsExchangeLoader.m_psModelFile, sDstFileNameUTF8);
//
// ### TERMINATE HOOPS EXCHANGE
//
// Check memory allocations
return (int)ListLeaks();
}