Init
This commit is contained in:
166
exchange/exchangesource/IncrementalLoad/IncrementalLoad.cpp
Normal file
166
exchange/exchangesource/IncrementalLoad/IncrementalLoad.cpp
Normal file
@@ -0,0 +1,166 @@
|
||||
/***********************************************************************************************************************
|
||||
*
|
||||
* 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 IncrementalLoad.cpp
|
||||
|
||||
Incremental loading technique allows a more fine-grained approach for loading files,
|
||||
which is especially beneficial when dealing with huge files
|
||||
(e.g. I want to load only item 26 and 72, not the whole file in one shot).
|
||||
|
||||
The only input is the file path, optionnal inputs are is the reading mode of the file and unload.
|
||||
|
||||
***********************************************************************************************************************/
|
||||
|
||||
#define _CRT_SECURE_NO_DEPRECATE 1
|
||||
#define INITIALIZE_A3D_API
|
||||
#include <A3DSDKIncludes.h>
|
||||
|
||||
#include "../common.hpp"
|
||||
|
||||
//######################################################################################################################
|
||||
A3DStatus stLoadRequiredProductOccurrence(A3DAsmProductOccurrence* pOcc,
|
||||
A3DAsmProductOccurrence* pRoot,
|
||||
A3DSDKHOOPSExchangeLoader& sHoopsExchangeLoader,
|
||||
A3DImport& sImport,
|
||||
A3DEReadGeomTessMode eMode,
|
||||
bool bWithUnload)
|
||||
{
|
||||
A3DStatus iRet = A3D_SUCCESS;
|
||||
|
||||
if (pRoot == NULL)
|
||||
{
|
||||
// trying to incremental load a part...
|
||||
return A3D_ERROR;
|
||||
}
|
||||
|
||||
sImport.m_sLoadData.m_sGeneral.m_eReadGeomTessMode = eMode;
|
||||
sImport.m_sLoadData.m_sIncremental.m_bLoadStructureOnly = false;
|
||||
sImport.m_sLoadData.m_sIncremental.m_ppProductOccurrences = &pOcc;
|
||||
sImport.m_sLoadData.m_sIncremental.m_pRootProductOccurrence = pRoot;
|
||||
sImport.m_sLoadData.m_sIncremental.m_uiProductOccurrencesSize = 1;
|
||||
|
||||
CHECK_RET(sHoopsExchangeLoader.Import(sImport));
|
||||
|
||||
if (bWithUnload)
|
||||
{
|
||||
CHECK_RET(A3DAsmModelFileUnloadParts(sHoopsExchangeLoader.m_psModelFile, 1, &pOcc));
|
||||
}
|
||||
|
||||
return iRet;
|
||||
}
|
||||
|
||||
//######################################################################################################################
|
||||
static A3DStatus stIncrementalLoadFromProductOccurrences(A3DAsmProductOccurrence* pProductOccurrence,
|
||||
A3DAsmProductOccurrence* pRoot,
|
||||
A3DSDKHOOPSExchangeLoader& sHoopsExchangeLoader,
|
||||
A3DImport& sImport,
|
||||
A3DEReadGeomTessMode eMode,
|
||||
bool bWithUnload)
|
||||
{
|
||||
// get the data
|
||||
A3DAsmProductOccurrenceData sProductOccurrenceData;
|
||||
A3D_INITIALIZE_DATA(A3DAsmProductOccurrenceData, sProductOccurrenceData);
|
||||
CHECK_RET(A3DAsmProductOccurrenceGet(pProductOccurrence, &sProductOccurrenceData));
|
||||
|
||||
// If the PO is a leaf, load the PO
|
||||
if (sProductOccurrenceData.m_uiPOccurrencesSize == 0)
|
||||
{
|
||||
stLoadRequiredProductOccurrence(pProductOccurrence, pRoot, sHoopsExchangeLoader, sImport, eMode, bWithUnload);
|
||||
}
|
||||
// If not, find leaves recursively
|
||||
else
|
||||
{
|
||||
for (A3DUns32 i = 0; i < sProductOccurrenceData.m_uiPOccurrencesSize; ++i)
|
||||
{
|
||||
stIncrementalLoadFromProductOccurrences(sProductOccurrenceData.m_ppPOccurrences[i], pProductOccurrence, sHoopsExchangeLoader, sImport, eMode, bWithUnload);
|
||||
}
|
||||
}
|
||||
A3DAsmProductOccurrenceGet(nullptr, &sProductOccurrenceData);
|
||||
return A3D_SUCCESS;
|
||||
}
|
||||
|
||||
static MY_CHAR acSrcFileName[_MAX_PATH * 2];
|
||||
static MY_CHAR acDstFileName[_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 > 5)
|
||||
{
|
||||
MY_PRINTF2("Usage:\n %s [input CAD file] [reading mode: 0=geom only, 1=geom+tess, 2=tess only] [with unload] [output LOG file]\n", ppcArgv[0]);
|
||||
MY_PRINTF(" Default output LOG file is [input CAD file]_Log.txt\n\n");
|
||||
return A3D_ERROR;
|
||||
}
|
||||
|
||||
A3DEReadGeomTessMode eMode = kA3DReadTessOnly;
|
||||
bool bWithUnload = true;
|
||||
|
||||
if (iArgc > 1) MY_STRCPY(acSrcFileName, ppcArgv[1]);
|
||||
else MY_STRCPY(acSrcFileName, DEFAULT_INPUT_CAD);
|
||||
if (iArgc > 2) eMode = (A3DEReadGeomTessMode)MY_ATOI(ppcArgv[2]);
|
||||
else eMode = kA3DReadTessOnly;
|
||||
if (iArgc > 3) bWithUnload = MY_ATOI(ppcArgv[3]) == 1;
|
||||
else bWithUnload = true;
|
||||
if (iArgc > 4) MY_STRCPY(acLogFileName, ppcArgv[4]);
|
||||
else MY_SPRINTF(acLogFileName, "%s_Log.txt", acDstFileName);
|
||||
GetLogFile(acLogFileName); // Initialize log file
|
||||
|
||||
//
|
||||
// ### INITIALIZE HOOPS EXCHANGE
|
||||
//
|
||||
|
||||
A3DSDKHOOPSExchangeLoader sHoopsExchangeLoader(_T(HOOPS_BINARY_DIRECTORY));
|
||||
CHECK_RET(sHoopsExchangeLoader.m_eSDKStatus);
|
||||
|
||||
// Initialize call backs
|
||||
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
|
||||
|
||||
//loading of the CAD file in incremental mode
|
||||
sImport.m_sLoadData.m_sIncremental.m_bLoadStructureOnly = true;
|
||||
A3DStatus iRet = sHoopsExchangeLoader.Import(sImport);
|
||||
if (iRet != A3D_SUCCESS && iRet != A3D_LOAD_MISSING_COMPONENTS)
|
||||
CHECK_RET(iRet);
|
||||
|
||||
// Get Model File
|
||||
A3DAsmModelFileData sModelFileData;
|
||||
A3D_INITIALIZE_DATA(A3DAsmModelFileData, sModelFileData);
|
||||
CHECK_RET(A3DAsmModelFileGet(sHoopsExchangeLoader.m_psModelFile, &sModelFileData));
|
||||
|
||||
// iterate on each root PO
|
||||
for (A3DUns32 i = 0; i < sModelFileData.m_uiPOccurrencesSize; ++i)
|
||||
{
|
||||
stIncrementalLoadFromProductOccurrences(sModelFileData.m_ppPOccurrences[i], NULL, sHoopsExchangeLoader, sImport, eMode, bWithUnload);
|
||||
}
|
||||
A3DAsmModelFileGet(nullptr, &sModelFileData);
|
||||
//
|
||||
// ### TERMINATE HOOPS EXCHANGE
|
||||
//
|
||||
|
||||
// Check memory allocations
|
||||
return (int)ListLeaks();
|
||||
}
|
||||
Reference in New Issue
Block a user