/*********************************************************************************************************************** * * Copyright (c) 2010 - 2022 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. * ***********************************************************************************************************************/ /** \file LoadMultiConfigCADFile.cpp This file demonstrates how to programmatically load CAD files that contain multiple configurations using HOOPS Exchange. The only input is the file path. ***********************************************************************************************************************/ #define _CRT_SECURE_NO_DEPRECATE 1 #define INITIALIZE_A3D_API #include #include "../common.hpp" //###################################################################################################################### A3DStatus stLoadMultiConfigFile(A3DSDKHOOPSExchangeLoader& sHoopsExchangeLoader, A3DImport& sImport) { A3DStatus iRet = A3D_SUCCESS; sImport.m_sLoadData.m_sGeneral.m_bReadSolids = true; sImport.m_sLoadData.m_sGeneral.m_bReadSurfaces = true; sImport.m_sLoadData.m_sGeneral.m_eReadGeomTessMode = kA3DReadGeomOnly; A3DUTF8Char* pcName = NULL; FILE* pLogFile = GetLogFile(); for(int i = 0; i < 2; ++i) { sImport.m_sLoadData.m_sMultiEntries.m_bLoadDefault = (i == 0) ? true : false; iRet = sHoopsExchangeLoader.Import(sImport); if(iRet == A3D_SUCCESS || iRet == A3D_LOAD_MULTI_MODELS_CADFILE || iRet == A3D_LOAD_MISSING_COMPONENTS) { A3DAsmModelFile* pModelFile=sHoopsExchangeLoader.m_psModelFile; sHoopsExchangeLoader.m_psModelFile = NULL; A3DAsmModelFileData sModelFileData; A3D_INITIALIZE_DATA(A3DAsmModelFileData, sModelFileData); CHECK_RET(A3DAsmModelFileGet(pModelFile, &sModelFileData)); // the first level of ProductOccurrences A3DAsmProductOccurrenceData sRootProductOccurrenceData; A3D_INITIALIZE_DATA(A3DAsmProductOccurrenceData, sRootProductOccurrenceData); CHECK_RET(A3DAsmProductOccurrenceGet(sModelFileData.m_ppPOccurrences[0], &sRootProductOccurrenceData)); fprintf(pLogFile, "\nNumber of configurations: %u with m_bLoadDefault=%i\n", sRootProductOccurrenceData.m_uiPOccurrencesSize, sImport.m_sLoadData.m_sMultiEntries.m_bLoadDefault); if(i == 1) //sLoadParametersData.m_sMultiEntries.m_bLoadDefault=false fprintf(pLogFile, "None of the configurations have been loaded\n"); A3DAsmProductOccurrenceData sProductOccurrenceData; A3D_INITIALIZE_DATA(A3DAsmProductOccurrenceData, sProductOccurrenceData); A3DRootBaseData sRootBaseData; A3D_INITIALIZE_DATA(A3DRootBaseData, sRootBaseData); for(unsigned int j = 0; j < sRootProductOccurrenceData.m_uiPOccurrencesSize; j++) { CHECK_RET(A3DAsmProductOccurrenceGet(sRootProductOccurrenceData.m_ppPOccurrences[j], &sProductOccurrenceData)); if(sProductOccurrenceData.m_uiProductFlags&A3D_PRODUCT_FLAG_CONFIG && sProductOccurrenceData.m_uiProductFlags&A3D_PRODUCT_FLAG_DEFAULT) { if(i == 0) //sLoadParametersData.m_sMultiEntries.m_bLoadDefault=true; { fprintf(pLogFile, "The config #%u is the default one.\n", j); // getting its name CHECK_RET(A3DRootBaseGet(sRootProductOccurrenceData.m_ppPOccurrences[j], &sRootBaseData)); pcName = (A3DUTF8Char*) malloc(A3DUns32(strlen(sRootBaseData.m_pcName))+1); strncpy(pcName, sRootBaseData.m_pcName, strlen(sRootBaseData.m_pcName)); pcName[strlen(sRootBaseData.m_pcName)] = '\0'; CHECK_RET(A3DRootBaseGet(NULL, &sRootBaseData)); fprintf(pLogFile, "The default configuration has been loaded.\n"); } } else { if(i == 0) fprintf(pLogFile, "The config #%u is not the default one, its children have not been loaded.\n", j); } fprintf(pLogFile, "Number of children of config #%u: %u.\n", j, sProductOccurrenceData.m_uiPOccurrencesSize); // don't forget to free the allocated data CHECK_RET(A3DAsmProductOccurrenceGet(NULL, &sProductOccurrenceData)); } // freeing the rest CHECK_RET(A3DAsmProductOccurrenceGet(NULL, &sRootProductOccurrenceData)); CHECK_RET(A3DAsmModelFileGet(NULL, &sModelFileData)); CHECK_RET(A3DAsmModelFileDelete(pModelFile)); } } // now we know the default configuration number, we can load it, or any other configuration needed sImport.m_sLoadData.m_sMultiEntries.m_bLoadDefault = false; sImport.m_sLoadData.m_sMultiEntries.m_uiEntriesSize = 1; sImport.m_sLoadData.m_sMultiEntries.m_ppcEntries = &pcName; sHoopsExchangeLoader.Import(sImport); // Your processing... return iRet; } static MY_CHAR acSrcFileName[_MAX_PATH * 2]; static MY_CHAR acLogFileName[_MAX_PATH * 2]; //###################################################################################################################### // Main function #ifdef _MSC_VER int wmain(A3DInt32 iArgc, A3DUniChar** ppcArgv) #else int main(A3DInt32 iArgc, A3DUTF8Char** ppcArgv) #endif { // // ### COMMAND LINE ARGUMENTS // if (iArgc > 3) { MY_PRINTF2("Usage:\n %s [input CAD file] [output LOG file]\n", ppcArgv[0]); MY_PRINTF(" Default output LOG file is [input CAD file]_Log.txt\n\n"); return A3D_ERROR; } if (iArgc > 1) MY_STRCPY(acSrcFileName, ppcArgv[1]); else MY_STRCPY(acSrcFileName, DEFAULT_INPUT_CAD); if (iArgc > 2) MY_STRCPY(acLogFileName, ppcArgv[2]); else MY_SPRINTF(acLogFileName, "%s_Log.txt", acSrcFileName); GetLogFile(acLogFileName); // Initialize log file // // ### INITIALIZE HOOPS EXCHANGE // A3DSDKHOOPSExchangeLoader sHoopsExchangeLoader(_T(HOOPS_BINARY_DIRECTORY)); CHECK_RET(sHoopsExchangeLoader.m_eSDKStatus); // Initialize callbacks 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 CHECK_RET(stLoadMultiConfigFile(sHoopsExchangeLoader, sImport)); // // ### TERMINATE HOOPS EXCHANGE // // Check memory allocations return (int)ListLeaks(); }