This commit is contained in:
ninja
2025-12-15 22:06:49 +08:00
commit 2b56cf87a8
225 changed files with 63711 additions and 0 deletions

View File

@@ -0,0 +1,403 @@
/***********************************************************************************************************************
*
* 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 MultiplePrc.cpp
This file demonstrates how to programmatically create and read multiple PRC files
from a CAD assembly using HOOPS Exchange.
The input is the CAD assembly file path and a directory.
The program generates multiple PRC files from this CAD assembly.
This mode is supported for the following format: V4, V5, ProE, UG, SLDW.
With other formats, only one PRC file is generated.
***********************************************************************************************************************/
#define _CRT_SECURE_NO_DEPRECATE 1
#include <string>
#define INITIALIZE_A3D_API
#include <A3DSDKIncludes.h>
#include "../common.hpp"
//######################################################################################################################
bool MakePath(const std::string& strPath);
std::string ExtractPath(const A3DUTF8Char* pcIn);
std::string ExtractFileName(const A3DUTF8Char* pcIn);
A3DStatus TestOutputFile(const std::string& strFileName);
static MY_CHAR acSrcFileName[_MAX_PATH * 2];
static MY_CHAR acDstPathName[_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
{
//
// ### 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));
//
// ### COMMAND LINE ARGUMENTS
//
if (iArgc > 4)
{
MY_PRINTF2("Usage:\n %s [input CAD file] [output PRC path] [output LOG file]\n", ppcArgv[0]);
MY_PRINTF(" Default output PRC path is from [input CAD file]\n");
MY_PRINTF(" Default output LOG file is [input CAD file]_Log.txt\n\n");
return A3D_ERROR;
}
A3DUTF8Char sSrcFileNameUTF8[_MAX_PATH];
if (iArgc > 1) MY_STRCPY(acSrcFileName, ppcArgv[1]);
else MY_STRCPY(acSrcFileName, DEFAULT_INPUT_CAD);
#ifdef _MSC_VER
A3DMiscUTF16ToUTF8(acSrcFileName, sSrcFileNameUTF8);
#else
MY_STRCPY(sSrcFileNameUTF8, acSrcFileName);
#endif
A3DUTF8Char sDstFileNameUTF8[_MAX_PATH];
if (iArgc > 2)
{
MY_STRCPY(acDstPathName, ppcArgv[2]);
#ifdef _MSC_VER
A3DMiscUTF16ToUTF8(acDstPathName, sDstFileNameUTF8);
#else
MY_STRCPY(sDstFileNameUTF8, acDstPathName);
#endif
}
else
{
std::string strPath = ExtractPath(sSrcFileNameUTF8);
strcpy(sDstFileNameUTF8, strPath.c_str());
}
if (iArgc > 3) MY_STRCPY(acLogFileName, ppcArgv[3]);
else MY_SPRINTF(acLogFileName, "%s_Log.txt", acSrcFileName);
GetLogFile(acLogFileName); // Initialize log file
//
// ### PROCESS SAMPLE CODE
//
std::string strMainFileName = ExtractFileName(sSrcFileNameUTF8);
std::string strOutDir = sDstFileNameUTF8;
// remove " from path (if found).
for (size_t iFound = strOutDir.find('"'); iFound != std::string::npos; iFound = strOutDir.find('"'))
strOutDir.erase(iFound, 1);
////////////////////////////////////////////////////////////////////////////
// Check input file and output directory.
////////////////////////////////////////////////////////////////////////////
if (FILE* pFile = fopen(sSrcFileNameUTF8, "rb"))
{
fclose(pFile);
}
else
{
fprintf(stderr, "cannot open input file %s\n", sSrcFileNameUTF8);
return A3D_LOAD_CANNOT_ACCESS_CADFILE;
}
////////////////////////////////////////////////////////////////////////////
// 2- Read input file in mode "tree only".
////////////////////////////////////////////////////////////////////////////
A3DImport sImport(acSrcFileName); // see A3DSDKInternalConvert.hxx for import and export detailed parameters
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);
////////////////////////////////////////////////////////////////////////////
// 3- Extract file names.
////////////////////////////////////////////////////////////////////////////
A3DUns32 nbFiles = 0, nbAssemblyFiles = 0, nbMissingFiles = 0;
A3DUTF8Char** ppPaths = NULL, ** ppAssemblyPaths = NULL, ** ppMissingPaths = NULL;
CHECK_RET(A3DAsmGetFilesPathFromModelFile(sHoopsExchangeLoader.m_psModelFile, &nbFiles, &ppPaths, &nbAssemblyFiles, &ppAssemblyPaths, &nbMissingFiles, &ppMissingPaths));
////////////////////////////////////////////////////////////////////////////
// Check consistency for this sample : if the input file doesn't need this pipeline, export it as a prc and avoid
// the "tree only" export and the reassembly.
////////////////////////////////////////////////////////////////////////////
const std::string strOutBaseFileName = strOutDir
#ifdef WIN32
+ "\\__"
#else
+ "/__"
#endif
+ strMainFileName;
if (nbFiles == 1 && strcmp(ppPaths[0], sSrcFileNameUTF8) == 0)
//The file found is a part or an assembly file. In order to not generate 3 output files (tree only, part
// file and re-assembled file) for one input file, we test this case and avoid the useless work.
{
// test output file writeability
const std::string strOutFileName = strOutBaseFileName + ".prc";
const A3DStatus eFileOK = TestOutputFile(strOutFileName);
if (eFileOK != A3D_SUCCESS)
return eFileOK;
CHECK_RET(A3DAsmModelFileDelete(sHoopsExchangeLoader.m_psModelFile));
sHoopsExchangeLoader.m_psModelFile = NULL;
sImport.m_sLoadData.m_sIncremental.m_bLoadStructureOnly = false;
iRet = sHoopsExchangeLoader.Import(sImport);
if (iRet != A3D_SUCCESS && iRet != A3D_LOAD_MISSING_COMPONENTS)
CHECK_RET(iRet);
A3DExport sExport(strOutFileName.c_str()); // see A3DSDKInternalConvert.hxx for import and export detailed parameters
CHECK_RET(sHoopsExchangeLoader.Export(sExport));
//
// ### TERMINATE HOOPS EXCHANGE
//
// Check memory allocations
return (int)ListLeaks();
}
//////////////////////////////////////////////////////////////////////////
// 4- make output path
//////////////////////////////////////////////////////////////////////////
if (MakePath(strOutDir) == false)
{
fprintf(stderr, "Cannot create output base folder: '%s'.\n", strOutDir.c_str());
}
//////////////////////////////////////////////////////////////////////////
// 5- export main file as an prc assembly
//////////////////////////////////////////////////////////////////////////
// test output file writability
const std::string strOutMainFileName = strOutBaseFileName + "Structure.prc";
const A3DStatus eFileOK = TestOutputFile(strOutMainFileName);
if (eFileOK != A3D_SUCCESS)
return eFileOK;
A3DExport sExport(strOutMainFileName.c_str()); // see A3DSDKInternalConvert.hxx for import and export detailed parameters
CHECK_RET(sHoopsExchangeLoader.Export(sExport));
CHECK_RET(A3DAsmModelFileDelete(sHoopsExchangeLoader.m_psModelFile));
sHoopsExchangeLoader.m_psModelFile = NULL;
//////////////////////////////////////////////////////////////////////////
// 6- create mapped file names for PRC part files
// export part as PRC
// incremental load for part with multiple configurations
//////////////////////////////////////////////////////////////////////////
sImport.m_sLoadData.m_sIncremental.m_bLoadStructureOnly = false;
sImport.m_sLoadData.m_sMultiEntries.m_bLoadDefault = false;
A3DUTF8Char** ppMappedPartPaths = (A3DUTF8Char**)CheckMalloc(size_t(nbFiles) * sizeof(A3DUTF8Char*));
struct Cleaner
{
size_t uNbFiles_;
A3DUTF8Char** ptr_;
Cleaner(size_t uNbFiles, A3DUTF8Char** ptr) :
uNbFiles_(uNbFiles),
ptr_(ptr)
{}
~Cleaner()
{
Release();
}
void Release()
{
for (unsigned ui = 0; ui < uNbFiles_; ++ui)
CheckFree(ptr_[ui]);
CheckFree(ptr_);
uNbFiles_ = 0;
ptr_ = nullptr;
}
} sCleaner(nbFiles, ppMappedPartPaths);
for (A3DUns32 i = 0; i < nbFiles; ++i)
{
A3DImport sSubImport(ppPaths[i]); // see A3DSDKInternalConvert.hxx for import and export detailed parameters
iRet = sHoopsExchangeLoader.Import(sSubImport);
A3DAsmModelFile* pCurrentModelFile = sHoopsExchangeLoader.m_psModelFile;
sHoopsExchangeLoader.m_psModelFile = NULL;
if (iRet == A3D_LOAD_CANNOT_ACCESS_CADFILE || iRet == A3D_LOAD_INVALID_FILE_FORMAT)
{
ppMappedPartPaths[i] = (A3DUTF8Char*)CheckMalloc( 10* sizeof(A3DUTF8Char));
strcpy(ppMappedPartPaths[i], "INVALID");
continue;
}
if (iRet == A3D_LOAD_MULTI_MODELS_CADFILE) //multi config!!
{
A3DAsmModelFileData sModelFileData;
A3D_INITIALIZE_DATA(A3DAsmModelFileData, sModelFileData);
A3DAsmModelFileGet(pCurrentModelFile, &sModelFileData);
A3DAsmProductOccurrence* pPO = sModelFileData.m_ppPOccurrences[0];
A3DAsmProductOccurrenceData sData;
A3D_INITIALIZE_DATA(A3DAsmProductOccurrenceData, sData);
A3DAsmProductOccurrenceGet(pPO, &sData);
for (A3DUns32 uiSonIndex = 0; uiSonIndex < sData.m_uiPOccurrencesSize; uiSonIndex++)
{
A3DImport sImportLocal(ppPaths[i]); // see A3DSDKInternalConvert.hxx for import and export detailed parameters
//connect the new read product occurrence with the current product occurrence
sImportLocal.m_sLoadData.m_sIncremental.m_uiProductOccurrencesSize = 1;
sImportLocal.m_sLoadData.m_sIncremental.m_ppProductOccurrences = &sData.m_ppPOccurrences[uiSonIndex];
sImportLocal.m_sLoadData.m_sIncremental.m_pRootProductOccurrence = pPO;
iRet = sHoopsExchangeLoader.Import(sImportLocal);
TEST_RET(iRet);
}
}
const std::string strCurrentPRCName = strOutDir
#ifdef WIN32
+ "\\"
#else
+ "/"
#endif
+ ExtractFileName(ppPaths[i]) + ".prc";
ppMappedPartPaths[i] = (A3DUTF8Char*)CheckMalloc((strCurrentPRCName.length() + 1) * sizeof(A3DUTF8Char));
strcpy(ppMappedPartPaths[i], strCurrentPRCName.c_str());
A3DExport sSubExport(ppMappedPartPaths[i]); // see A3DSDKInternalConvert.hxx for import and export detailed parameters
sHoopsExchangeLoader.m_psModelFile = pCurrentModelFile;
CHECK_RET(sHoopsExchangeLoader.Export(sSubExport));
CHECK_RET(A3DAsmModelFileDelete(sHoopsExchangeLoader.m_psModelFile));
sHoopsExchangeLoader.m_psModelFile = NULL;
}
//////////////////////////////////////////////////////////////////////////
// 7 - Rebuild part
//////////////////////////////////////////////////////////////////////////
A3DAsmModelFile* pOutModelFile = NULL;
A3DRWParamsLoadData sRPartParam;
A3D_INITIALIZE_DATA(A3DRWParamsLoadData, sRPartParam);
sRPartParam.m_sGeneral.m_bReadSolids = true;
sRPartParam.m_sGeneral.m_bReadSurfaces = true;
sRPartParam.m_sGeneral.m_eReadGeomTessMode = kA3DReadGeomAndTess;
sRPartParam.m_sMultiEntries.m_bLoadDefault = true;
// sRPartParam.m_sMultiEntries.m_bLoadDefault = false;
// A3DUTF8Char* pcName = "Full";//"Chassis and Fuel Tank"
// sRPartParam.m_sMultiEntries.m_ppcEntries = &pcName;
// sRPartParam.m_sMultiEntries.m_uiEntriesSize = 1;
CHECK_RET(A3DAsmModelFileLoadFromMultiplePrcFile(strOutMainFileName.c_str(),
nbFiles,
(const A3DUTF8Char**)ppPaths,
(const A3DUTF8Char**)ppMappedPartPaths,
&sRPartParam,
&pOutModelFile));
////////////////////////////////////////////////////////////////////////////
// 8- Export final file
////////////////////////////////////////////////////////////////////////////
A3DExport sFinalExport((strOutBaseFileName + "All.prc").c_str());
sHoopsExchangeLoader.m_psModelFile = pOutModelFile;
CHECK_RET(sHoopsExchangeLoader.Export(sFinalExport));
CHECK_RET(A3DAsmGetFilesPathFromModelFile(NULL, &nbFiles, &ppPaths, &nbAssemblyFiles, &ppAssemblyPaths,
&nbMissingFiles, &ppMissingPaths));
sCleaner.Release();
//
// ### TERMINATE HOOPS EXCHANGE
//
// Check memory allocations
return (int)ListLeaks();
}
//######################################################################################################################
// Recursively creates the folder path if it does not exist
// Returns true if the operation succeeds or if the folder already exists. False otherwise.
#ifdef _MSC_VER
bool MakePath(const std::string& strPath)
{
if (CreateDirectoryA(strPath.c_str(), 0) == 0)
{
return GetLastError() == ERROR_ALREADY_EXISTS;
}
return true;
}
#else
#include <sys/stat.h>
#include <errno.h>
bool MakePath(const std::string& strPath)
{
if (mkdir(strPath.c_str(), ACCESSPERMS) == -1)
{
if (errno == EEXIST)
{
return true;
}
return false;
}
return true;
}
#endif
//######################################################################################################################
std::string ExtractPath(const A3DUTF8Char* pcIn)
{
const std::string strIn(pcIn);
size_t lastSlash = strIn.rfind("/");
if (lastSlash == std::string::npos)
lastSlash = strIn.rfind("\\");
return strIn.substr(0, lastSlash + 1);
}
//######################################################################################################################
std::string ExtractFileName(const A3DUTF8Char* pcIn)
{
const std::string strIn(pcIn);
size_t lastSlash = strIn.rfind("/");
if (lastSlash == std::string::npos)
lastSlash = strIn.rfind("\\");
return strIn.substr(lastSlash + 1);
}
//######################################################################################################################
A3DStatus TestOutputFile(const std::string& strFileName)
{
if (FILE* pFile = fopen(strFileName.c_str(), "wb"))
{
fclose(pFile);
return A3D_SUCCESS;
}
else
{
fprintf(stderr, "cannot write output file %s\n", strFileName.c_str());
return A3D_WRITE_INVALID_FILE_NAME;
}
}

View File

@@ -0,0 +1,167 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{8B90DC19-E9AC-4D8C-A8E5-5190A986F9A0}</ProjectGuid>
<RootNamespace>MultiplePRCFiles</RootNamespace>
<Keyword>Win32Proj</Keyword>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v145</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v145</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v145</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v145</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="$(SolutionDir)\HOOPSExchangePublishSample.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="$(SolutionDir)\HOOPSExchangePublishSample.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="$(SolutionDir)\HOOPSExchangePublishSample.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="$(SolutionDir)\HOOPSExchangePublishSample.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>12.0.30501.0</_ProjectFileVersion>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>false</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<PrecompiledHeader />
<WarningLevel>Level4</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<SDLCheck>false</SDLCheck>
</ClCompile>
<Link>
<AdditionalLibraryDirectories>..\..\bin;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<TargetMachine>MachineX86</TargetMachine>
<AdditionalDependencies>legacy_stdio_float_rounding.obj;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Midl>
<TargetEnvironment>X64</TargetEnvironment>
</Midl>
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>false</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<PrecompiledHeader />
<WarningLevel>Level4</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<SDLCheck>false</SDLCheck>
</ClCompile>
<Link>
<AdditionalLibraryDirectories>..\..\bin;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<TargetMachine>MachineX64</TargetMachine>
<AdditionalDependencies>legacy_stdio_float_rounding.obj;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<Optimization>MaxSpeed</Optimization>
<IntrinsicFunctions>true</IntrinsicFunctions>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<FunctionLevelLinking>true</FunctionLevelLinking>
<PrecompiledHeader />
<WarningLevel>Level4</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<SDLCheck>false</SDLCheck>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<TargetMachine>MachineX86</TargetMachine>
<AdditionalDependencies>legacy_stdio_float_rounding.obj;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Midl>
<TargetEnvironment>X64</TargetEnvironment>
</Midl>
<ClCompile>
<Optimization>MaxSpeed</Optimization>
<IntrinsicFunctions>true</IntrinsicFunctions>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<FunctionLevelLinking>true</FunctionLevelLinking>
<PrecompiledHeader />
<WarningLevel>Level4</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<SDLCheck>false</SDLCheck>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<TargetMachine>MachineX64</TargetMachine>
<AdditionalDependencies>legacy_stdio_float_rounding.obj;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="MultiplePRC.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="MultiplePRC.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,476 @@
/***********************************************************************************************************************
*
* 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 MultiplePrc.cpp
This file demonstrates how to programmatically create and read multiple PRC files
from a CAD assembly using HOOPS Exchange.
The input is the CAD assembly file path and a directory.
The program generates multiple PRC files from this CAD assembly.
This mode is supported for the following format: V4, V5, ProE, UG, SLDW.
With other formats, only one PRC file is generated.
***********************************************************************************************************************/
#define _CRT_SECURE_NO_DEPRECATE 1
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <set>
#include <string>
#include <algorithm>
#define INITIALIZE_A3D_API
#include <A3DSDKIncludes.h>
#include <direct.h>
//######################################################################################################################
A3DVoid A3DCheckFree(A3DPtr ptr)
{
free(ptr);
}
//######################################################################################################################
A3DPtr A3DCheckMalloc(size_t uiToAlloc)
{
return malloc(uiToAlloc);
}
//######################################################################################################################
#define CHECK_RET(function_call) {\
iRet = function_call; if(iRet != A3D_SUCCESS) { std::cout << "Error number=" << iRet << std::endl; return iRet; }\
}
//######################################################################################################################
std::string ExtractFileName(const A3DUTF8Char* pcIn)
{
std::string strIn(pcIn);
int lastSlash = (int) strIn.rfind("/");
if(lastSlash < 0)
lastSlash = (int) strIn.rfind("\\");
std::string tmp = strIn.substr(size_t(lastSlash)+1);
return tmp;
}
//######################################################################################################################
std::string ExtractFilePath(const A3DUTF8Char* pcIn)
{
std::string strIn(pcIn);
int lastSlash = (int) strIn.rfind("/");
if(lastSlash < 0)
lastSlash = (int) strIn.rfind("\\");
std::string tmp = strIn.substr(0,size_t(lastSlash));
return tmp;
}
//######################################################################################################################
std::string ExtractRelativePath(const A3DUTF8Char* pcIn,const A3DUTF8Char* pcDirRoot)
{
std::string strTotalPath = ExtractFilePath(pcIn);
std::string strRootPath(pcDirRoot);
std::string strRelativePath;
size_t uiTotalPathSize = strTotalPath.size();
size_t uiRootPathSize = strRootPath.size();
if(uiTotalPathSize > uiRootPathSize)
{
strRelativePath = strTotalPath.substr(uiRootPathSize);
}
return strRelativePath;
}
//######################################################################################################################
bool DirExists(const std::string& dirName_in)
{
DWORD ftyp = GetFileAttributesA(dirName_in.c_str());
if (ftyp == INVALID_FILE_ATTRIBUTES)
return false;
if (ftyp & FILE_ATTRIBUTE_DIRECTORY)
return true;
return false;
}
//######################################################################################################################
std::string ExtractChoreFileName(std::string pcIn)
{
std::string strIn(pcIn);
int lastPoint = (int) strIn.rfind(".");
std::string tmp = strIn.substr(0, size_t(lastPoint));
return tmp;
}
//######################################################################################################################
int TreatFile(A3DSDKHOOPSExchangeLoader &sHoopsExchangeLoader,
A3DUTF8Char** ppMappedNativePaths,
A3DUTF8Char** ppMappedPRCPaths,
unsigned int &idxmap,
bool bIsAssembly,
char* acUTF8FileName, char* acUTF8InDir, char* acUTF8OutDir)
{
int iRet;
std::string strMainFileName = acUTF8FileName;
// --- REREAD the native file without dependencies
if(sHoopsExchangeLoader.m_psModelFile != NULL)
A3DAsmModelFileDelete(sHoopsExchangeLoader.m_psModelFile);
sHoopsExchangeLoader.m_psModelFile = NULL;
A3DImport sImport2(strMainFileName.c_str());
sImport2.m_sLoadData.m_sIncremental.m_bLoadNoDependencies = true;
iRet = sHoopsExchangeLoader.Import(sImport2);
if(iRet != A3D_SUCCESS && iRet != A3D_LOAD_MISSING_COMPONENTS && iRet != A3D_LOAD_MULTI_MODELS_CADFILE)
return iRet;
// --- EXPORT as PRC
std::string strRelativePath = ExtractRelativePath(strMainFileName.c_str(), acUTF8InDir);
std::string strChorefilename = ExtractFileName(strMainFileName.c_str());
std::string strOutMainFileName = acUTF8OutDir;
strOutMainFileName += strRelativePath;
if( DirExists(strOutMainFileName) == false)
{
#ifdef _MSC_VER
_mkdir(strOutMainFileName.c_str());
#else
mkdir(strOutMainFileName.c_str());
#endif
}
strOutMainFileName += "\\__";
strOutMainFileName += strChorefilename;
strOutMainFileName += ".prc";
A3DExport sExport(strOutMainFileName.c_str());
CHECK_RET(sHoopsExchangeLoader.Export(sExport));
// update the map NATIVE-PRC
std::string strCurrentPRCName = strMainFileName;
strCurrentPRCName += ".prc";
ppMappedNativePaths[idxmap] = (A3DUTF8Char*) A3DCheckMalloc(1024 * sizeof(A3DUTF8Char));
strcpy(ppMappedNativePaths[idxmap], strMainFileName.c_str()); //acUTF8FileName if we don't want the path
ppMappedPRCPaths[idxmap] = (A3DUTF8Char*) A3DCheckMalloc(1024 * sizeof(A3DUTF8Char));
strcpy(ppMappedPRCPaths[idxmap], strOutMainFileName.c_str()); //strCurrentPRCName.c_str()) if we don't want the path
idxmap++;
CHECK_RET(A3DAsmModelFileDelete(sHoopsExchangeLoader.m_psModelFile));
sHoopsExchangeLoader.m_psModelFile = NULL;
return 0;
}
//######################################################################################################################
bool SortByExtensionInPath(const std::string& strExtensionAsm,
const std::string& strExtensionPrt,
const std::string& strTestingPath,
const std::string& strPath,
std::set<std::string>& a_rsCollectedAsmFilesPath,
std::set<std::string>& a_rsCollectedPartFilesPath)
{
char sDrive[256];
char sDir[256];
char sFileName[256];
char sExtension[256];
_splitpath(strTestingPath.c_str(),sDrive,sDir,sFileName,sExtension);
std::string szExtension(sExtension);
std::transform(szExtension.begin(), szExtension.end(), szExtension.begin(), ::tolower);
size_t sAsm = szExtension.find(strExtensionAsm);
size_t sPrt = szExtension.find(strExtensionPrt);
if(sAsm == std::string::npos && sPrt == std::string::npos)
return false;
if(sAsm > sPrt)
a_rsCollectedAsmFilesPath.insert(strPath);
else
a_rsCollectedPartFilesPath.insert(strPath);
return true;
}
bool SortFilePath(const A3DEModellerType& eType, const std::string& a_rsPath,
std::set<std::string>& a_rsCollectedAsmFilesPath,
std::set<std::string>& a_rsCollectedPartFilesPath)
{
switch(eType)
{
case kA3DModellerProE:
{
std::string szRealPath = a_rsPath;
size_t iDotPos = a_rsPath.find_last_of('.');
if(iDotPos != std::string::npos)
szRealPath.erase (szRealPath.begin()+iDotPos, szRealPath.end());
return SortByExtensionInPath("asm", "prt", szRealPath,a_rsPath,a_rsCollectedAsmFilesPath,a_rsCollectedPartFilesPath);
}
case kA3DModellerSlw:
return SortByExtensionInPath("sldasm", "sldprt",a_rsPath, a_rsPath,a_rsCollectedAsmFilesPath,a_rsCollectedPartFilesPath);
case kA3DModellerCatiaV5:
return SortByExtensionInPath("catproduct", "catpart", a_rsPath,a_rsPath,a_rsCollectedAsmFilesPath,a_rsCollectedPartFilesPath);
case kA3DModellerCatia:
return SortByExtensionInPath("session", "model", a_rsPath,a_rsPath,a_rsCollectedAsmFilesPath,a_rsCollectedPartFilesPath);
case kA3DModellerInventor:
return SortByExtensionInPath("iam", "ipt", a_rsPath,a_rsPath,a_rsCollectedAsmFilesPath,a_rsCollectedPartFilesPath);
case kA3DModellerSE:
return SortByExtensionInPath("asm", "par", a_rsPath,a_rsPath,a_rsCollectedAsmFilesPath,a_rsCollectedPartFilesPath);
default : return false;
}
}
//######################################################################################################################
A3DStatus GetAllFileDependenciesFromFilelist(A3DUTF8Char*& a_rpcFilelist,
std::set<std::string>& a_rsCollectedAsmFilesPath,
std::set<std::string>& a_rsCollectedPartFilesPath)
{
std::ifstream oFile;
oFile.open(a_rpcFilelist);
while (!oFile.eof())
{
std::string szFilePath;
getline(oFile,szFilePath);
A3DEModellerType eType;
A3DStatus iRet = A3DGetFileFormat(szFilePath.c_str(), &eType);
if(iRet != A3D_SUCCESS)
return iRet;
if(!SortFilePath(eType,szFilePath,a_rsCollectedAsmFilesPath, a_rsCollectedPartFilesPath))
return A3D_LOAD_MISSING_COMPONENTS;
}
oFile.close();
return A3D_SUCCESS;
}
//######################################################################################################################
A3DStatus GetAllFileDependencies(std::string& a_rszCurFile,
A3DSDKHOOPSExchangeLoader& a_rsHoopsExchangeLoader,
std::set<std::string>& a_rsCollectedAsmFilesPath,
std::set<std::string>& a_rsCollectedPartFilesPath)
{
// Load file
A3DImport sImport(a_rszCurFile.c_str());
sImport.m_sLoadData.m_sIncremental.m_bLoadNoDependencies = true;
A3DStatus iRet = a_rsHoopsExchangeLoader.Import(sImport);
if(iRet != A3D_SUCCESS && iRet != A3D_LOAD_MISSING_COMPONENTS && iRet != A3D_LOAD_MULTI_MODELS_CADFILE)
return iRet;
// Extract sub-file names
A3DUns32 i = 0;
A3DUns32 nbPartFiles = 0;
A3DUTF8Char** ppPartPaths = NULL;
A3DUns32 nbAssemblyFiles = 0;
A3DUTF8Char** ppAssemblyPaths = NULL;
A3DUns32 uNbMissingFiles = 0;
A3DUTF8Char** ppMissingFilesPaths = NULL;
CHECK_RET(A3DAsmGetFilesPathFromModelFile(a_rsHoopsExchangeLoader.m_psModelFile, &nbPartFiles, &ppPartPaths, &nbAssemblyFiles, &ppAssemblyPaths, &uNbMissingFiles, &ppMissingFilesPaths));
for(i = 0; i < nbAssemblyFiles; i ++)
{
a_rsCollectedAsmFilesPath.insert(ppAssemblyPaths[i]);
}
for(i = 0; i < nbPartFiles; i ++)
{
a_rsCollectedPartFilesPath.insert(ppPartPaths[i]);
a_rsCollectedAsmFilesPath.erase(ppPartPaths[i]);
}
// Free model file
if(a_rsHoopsExchangeLoader.m_psModelFile != NULL)
{
A3DAsmModelFileDelete(a_rsHoopsExchangeLoader.m_psModelFile);
a_rsHoopsExchangeLoader.m_psModelFile = NULL;
}
// Load Sub assembly files
for(i = 0; i < nbAssemblyFiles; i ++)
{
std::string szSubFileName(ppAssemblyPaths[i]);
if(szSubFileName != a_rszCurFile)
{
GetAllFileDependencies(szSubFileName, a_rsHoopsExchangeLoader, a_rsCollectedAsmFilesPath, a_rsCollectedPartFilesPath);
}
}
// Free filenames intermediate storage
CHECK_RET(A3DAsmGetFilesPathFromModelFile(NULL, &nbPartFiles, &ppPartPaths, &nbAssemblyFiles, &ppAssemblyPaths, &uNbMissingFiles, &ppMissingFilesPaths));
return A3D_SUCCESS;
}
//######################################################################################################################
// Main function
#ifdef _MSC_VER
int wmain(A3DInt32 iArgc, A3DUniChar** ppcArgv)
#else
int main(int iArgc, A3DUTF8Char** ppcArgv)
#endif
{
if(iArgc != 4 && iArgc != 5)
{
#ifdef _MSC_VER
_tprintf(_T("Usage:\n %s <Roots CAD file path> <Input CAD File directory> <Output directory path> <Filelist (optional)>\n"), ppcArgv[0]);
#else
printf("Usage:\n %s <input CAD file path> <Output directory path>\n", ppcArgv[0]);
#endif
return A3D_ERROR;
}
/////////////////////////////////////////////
// 1- Initialize HOOPS Exchange.
/////////////////////////////////////////////
#ifdef _MSC_VER
# ifdef _WIN64
const TCHAR* pcLibPath = _T("..\\..\\..\\..\\bin\\win64\\");
# else
const TCHAR* pcLibPath = _T("..\\..\\..\\..\\bin\\win32\\");
# endif
A3DUTF8Char acUTF8FileName[MAX_PATH*4];
A3DUTF8Char acUTF8InDir[MAX_PATH*4];
A3DUTF8Char acUTF8OutDir[MAX_PATH*4];
A3DUTF8Char* acUTF8FileList = NULL;
#else
# ifdef X32
const A3DUTF8Char* pcLibPath = "../../../../bin/linux32";
# else
const A3DUTF8Char* pcLibPath = "../../../../bin/linux64";
# endif
A3DUTF8Char* acUTF8FileName = ppcArgv[1];
A3DUTF8Char* acUTF8InDir = ppcArgv[2];
A3DUTF8Char* acUTF8OutDir = ppcArgv[3];
A3DUTF8Char* acUTF8FileList = ppcArgv[4];
#endif
A3DInt32 iRet = A3D_SUCCESS;
A3DSDKHOOPSExchangeLoader sHoopsExchangeLoader(pcLibPath);
if (sHoopsExchangeLoader.m_eSDKStatus!=A3D_SUCCESS)
return sHoopsExchangeLoader.m_eSDKStatus;
#ifdef _MSC_VER
A3DMiscUnicodeToUTF8((A3DUTF8Char*) ppcArgv[1], acUTF8FileName);
A3DMiscUnicodeToUTF8((A3DUTF8Char*) ppcArgv[2], acUTF8InDir);
A3DMiscUnicodeToUTF8((A3DUTF8Char*) ppcArgv[3], acUTF8OutDir);
if(ppcArgv[4])
{
acUTF8FileList = new A3DUTF8Char[MAX_PATH*4];
A3DMiscUnicodeToUTF8((A3DUTF8Char*) ppcArgv[4], acUTF8FileList);
}
#endif
std::string strMainFileName = ExtractFileName(acUTF8FileName);
std::string strInMainFileName = acUTF8FileName;
// init map NATIVE-PRC
const int MAXFILES = 100;
A3DUTF8Char** ppMappedNativePaths = (A3DUTF8Char**) A3DCheckMalloc(MAXFILES * sizeof(A3DUTF8Char*));
A3DUTF8Char** ppMappedPRCPaths = (A3DUTF8Char**) A3DCheckMalloc(MAXFILES * sizeof(A3DUTF8Char*));
unsigned int idxmap = 0;
////////////////////////////////////////////////////////////////////////////
// load the model and get the list of files
////////////////////////////////////////////////////////////////////////////
// --- EXTRACT file names for sons
std::set<std::string> sAsmFilesPath;
std::set<std::string> sPartFilesPath;
if(acUTF8FileList)
{
iRet = GetAllFileDependenciesFromFilelist(acUTF8FileList, sAsmFilesPath, sPartFilesPath);
if(iRet != A3D_SUCCESS)
return iRet;
}
else
{
iRet = GetAllFileDependencies(strInMainFileName, sHoopsExchangeLoader, sAsmFilesPath, sPartFilesPath);
if(iRet != A3D_SUCCESS && iRet != A3D_LOAD_MISSING_COMPONENTS && iRet != A3D_LOAD_MULTI_MODELS_CADFILE)
return iRet;
}
////////////////////////////////////////////////////////////////////////////
// 1- build a PRC for each component in the assembly,
// and update the map NATIVE-PRC
////////////////////////////////////////////////////////////////////////////
// 1-a Roots
if(sAsmFilesPath.find(acUTF8FileName) == sAsmFilesPath.end()) // add root file if it's not already registered in sAsmFilesPath
{
TreatFile(sHoopsExchangeLoader,ppMappedNativePaths,ppMappedPRCPaths,idxmap ,
true, acUTF8FileName, acUTF8InDir, acUTF8OutDir);
}
//1-b Assemblies
std::set<std::string>::iterator itAsmPathCur = sAsmFilesPath.begin();
std::set<std::string>::iterator itAsmPathEnd = sAsmFilesPath.end();
for(; itAsmPathCur != itAsmPathEnd; itAsmPathCur++)
{
TreatFile(sHoopsExchangeLoader,ppMappedNativePaths,ppMappedPRCPaths,idxmap ,
true, (char*) (*itAsmPathCur).c_str(), acUTF8InDir, acUTF8OutDir);
}
//1-c Part
std::set<std::string>::iterator itPartPathCur = sPartFilesPath.begin();
std::set<std::string>::iterator itPartPathEnd = sPartFilesPath.end();
for(; itPartPathCur != itPartPathEnd; itPartPathCur++)
{
TreatFile(sHoopsExchangeLoader,ppMappedNativePaths,ppMappedPRCPaths,idxmap ,
false, (char*) (*itPartPathCur).c_str(), acUTF8InDir, acUTF8OutDir);
}
////////////////////////////////////////////////////////////////////////////
// 2- now simulate an assembly reconstruction starting from the root file with all PRC chunks
////////////////////////////////////////////////////////////////////////////
std::string strOutMainFileName = acUTF8OutDir;
strOutMainFileName += "\\__";
strOutMainFileName += strMainFileName;
strOutMainFileName += ".prc";
A3DAsmModelFile* pOutModelFile = NULL;
A3DRWParamsLoadData sRPartParam;
A3D_INITIALIZE_DATA(A3DRWParamsLoadData, sRPartParam);
sRPartParam.m_sGeneral.m_bReadSolids = true;
sRPartParam.m_sGeneral.m_bReadSurfaces = true;
sRPartParam.m_sGeneral.m_bReadWireframes = true;
sRPartParam.m_sGeneral.m_eReadGeomTessMode = kA3DReadGeomAndTess;
sRPartParam.m_sGeneral.m_bReadHiddenObjects = true;
//sRPartParam.m_sMultiEntries.m_bLoadDefault = true;
CHECK_RET(A3DAsmModelFileLoadFromPRCFiles(
strOutMainFileName.c_str(),
idxmap,
(const A3DUTF8Char**)ppMappedPRCPaths,
(const A3DUTF8Char**)ppMappedNativePaths,
&sRPartParam,
&pOutModelFile));
// --- Export the rebuilt assembly to test the result
std::string strOut = acUTF8OutDir;
strOut += "\\__";
strOut += strMainFileName;
strOut += "AllLoaded.prc";
A3DExport sFinalExport(strOut.c_str());
sHoopsExchangeLoader.m_psModelFile = pOutModelFile;
CHECK_RET(sHoopsExchangeLoader.Export(sFinalExport));
for(unsigned ui = 0; ui < idxmap; ++ui)
{
A3DCheckFree(ppMappedPRCPaths[ui]);
}
A3DCheckFree(ppMappedPRCPaths);
delete acUTF8FileList;
acUTF8FileList = NULL;
return A3D_SUCCESS;
}