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,194 @@
/***********************************************************************************************************************
*
* 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 BrepAdaptor.cpp
The B-rep used by HOOPS Exchange may not be completely compatible with modeling systems that do not support the full range of B-rep as employed by PRC. A3DCopyAndAdaptBrepModel attempts to convert PRC B-rep into a format that is compatible with your system.
This program demonstrates how to programmatically adapt B-rep models to your particular needs using HOOPS Exchange. B-rep
is always found in this hierarchy:
Model file > Product occurrence > Part definition > B-rep
The functions below attempt to find the B-rep entities by traversing the model tree.
This program reads a model file and outputs a PRC file. Specify these files on the command line (see 'Usage').
- Load a CAD file
- Traverse the entire data structure
- Call A3DCopyAndAdaptBrepModel for each BrepModels.
- Copy inputs BrepModels.
- Selected Geometricals surfaces are converted to nurbs.
- Faces are split.
- UV Curves are computed.
- New modified data are populated
- PRC is exported from the modified data
***********************************************************************************************************************/
#define INITIALIZE_A3D_API
#include <A3DSDKIncludes.h>
#include "../common.hpp"
static MY_CHAR acSrcFileName[_MAX_PATH * 2];
static MY_CHAR acDstFileName[_MAX_PATH * 2];
static MY_CHAR acLogFileName[_MAX_PATH * 2];
//######################################################################################################################
#ifdef _MSC_VER
int wmain(A3DInt32 iArgc, A3DUniChar** ppcArgv)
#else
int main(A3DInt32 iArgc, A3DUTF8Char** ppcArgv)
#endif
{
//
// ### COMMAND LINE ARGUMENTS
//
if (iArgc > 4)
{
MY_PRINTF2("Usage:\n %s [input CAD file] [output CAD file] [output LOG file]\n", ppcArgv[0]);
MY_PRINTF(" Default output CAD file is [input CAD file].prc\n");
MY_PRINTF(" Default output LOG file is [output 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(acDstFileName, ppcArgv[2]);
else MY_SPRINTF(acDstFileName, "%s.prc", 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));
CHECK_RET(sHoopsExchangeLoader.m_eSDKStatus);
CHECK_RET(A3DDllSetCallbacksMemory(CheckMalloc, CheckFree));
CHECK_RET(A3DDllSetCallbacksReport(PrintLogMessage, PrintLogWarning, PrintLogError));
//
// ### PROCESS SAMPLE CODE
//
// specify input file
A3DImport sImport(acSrcFileName); // see A3DSDKInternalConvert.hxx for import and export detailed parameters
A3DStatus iRet = sHoopsExchangeLoader.Import(sImport);
if (iRet != A3D_SUCCESS && iRet != A3D_LOAD_MISSING_COMPONENTS)
CHECK_RET(iRet);
const A3DUns32 NUM_VALID_SURFACES = 11;
A3DUns32 ACCEPTED_SURFACES[NUM_VALID_SURFACES] = {
kA3DTypeSurfBlend01,
//kA3DTypeSurfBlend02,
//kA3DTypeSurfBlend03,
kA3DTypeSurfNurbs,
kA3DTypeSurfCone,
kA3DTypeSurfCylinder,
kA3DTypeSurfCylindrical,
//kA3DTypeSurfOffset,
//kA3DTypeSurfPipe,
kA3DTypeSurfPlane,
kA3DTypeSurfRuled,
kA3DTypeSurfSphere,
//kA3DTypeSurfRevolution,
kA3DTypeSurfExtrusion,
//kA3DTypeSurfFromCurves,
kA3DTypeSurfTorus,
kA3DTypeSurfTransform,
//kA3DTypeSurfBlend04,
};
const A3DUns32 NUM_VALID_CURVES = 13;
A3DUns32 ACCEPTED_CURVES[NUM_VALID_CURVES] = {
//kA3DTypeCrvBase,
//kA3DTypeCrvBlend02Boundary,
kA3DTypeCrvNurbs,
kA3DTypeCrvCircle,
kA3DTypeCrvComposite,
kA3DTypeCrvOnSurf,
kA3DTypeCrvEllipse,
kA3DTypeCrvEquation,
kA3DTypeCrvHelix,
kA3DTypeCrvHyperbola,
//kA3DTypeCrvIntersection,
kA3DTypeCrvLine,
kA3DTypeCrvOffset,
kA3DTypeCrvParabola,
kA3DTypeCrvPolyLine,
kA3DTypeCrvTransform,
};
A3DCopyAndAdaptBrepModelData sCopyAndAdaptBrepModelData;
A3D_INITIALIZE_DATA(A3DCopyAndAdaptBrepModelData, sCopyAndAdaptBrepModelData);
sCopyAndAdaptBrepModelData.m_bUseSameParam = false;
sCopyAndAdaptBrepModelData.m_dTol = 1e-3;
sCopyAndAdaptBrepModelData.m_bDeleteCrossingUV = false;
sCopyAndAdaptBrepModelData.m_bAllowUVCrossingSeams = false;
sCopyAndAdaptBrepModelData.m_bSplitFaces = false;
sCopyAndAdaptBrepModelData.m_bSplitClosedFaces = false;
sCopyAndAdaptBrepModelData.m_bForceComputeUV = true;
sCopyAndAdaptBrepModelData.m_bForceCompute3D = false;
sCopyAndAdaptBrepModelData.m_uiAcceptableSurfacesSize = NUM_VALID_SURFACES;
sCopyAndAdaptBrepModelData.m_puiAcceptableSurfaces = &ACCEPTED_SURFACES[0];
sCopyAndAdaptBrepModelData.m_uiAcceptableCurvesSize = NUM_VALID_CURVES;
sCopyAndAdaptBrepModelData.m_puiAcceptableCurves = &ACCEPTED_CURVES[0];
sCopyAndAdaptBrepModelData.m_bContinueOnError = true;
A3DUns32 uiNbErrors = 0;
A3DCopyAndAdaptBrepModelErrorData *pErrors;
iRet = A3DAdaptAndReplaceAllBrepInModelFileAdvanced(sHoopsExchangeLoader.m_psModelFile, &sCopyAndAdaptBrepModelData, &uiNbErrors, &pErrors);
if ((iRet == A3D_SUCCESS || iRet == A3D_TOOLS_CONTINUE_ON_ERROR) && uiNbErrors > 0)
{
for (A3DUns32 i = 0; i < uiNbErrors; i++)
{
A3DCopyAndAdaptBrepModelErrorData* pCurrentError = &pErrors[i];
fprintf(GetLogFile(), "----------\n");
//see A3DSDKTypes.h for entity type
A3DEEntityType entityType;
CHECK_RET(A3DEntityGetType(pCurrentError->m_pEntity, &entityType));
fprintf(GetLogFile(), "Error on entity type........: %s(%d)\n", A3DMiscGetEntityTypeMsg(entityType), entityType);
fprintf(GetLogFile(), "Error on topological type...: %s(%d)\n", A3DMiscGetEntityTypeMsg((A3DEEntityType)pCurrentError->m_paiErrors[0]), pCurrentError->m_paiErrors[0]);
fprintf(GetLogFile(), "Status......................: %s(%d)\n", A3DMiscGetErrorMsg((A3DStatus)pCurrentError->m_paiErrors[1]), pCurrentError->m_paiErrors[1]);
fprintf(GetLogFile(), "The error is on the ");
A3DUns32 numIndex = pCurrentError->m_paiErrors[2];
if (numIndex == 0) fprintf(GetLogFile(), "BREP");
if (numIndex >= 1) fprintf(GetLogFile(), "Connex: %d", pCurrentError->m_paiErrors[3]);
if (numIndex >= 2) fprintf(GetLogFile(), ", Shell: %d", pCurrentError->m_paiErrors[4]);
if (numIndex >= 3) fprintf(GetLogFile(), ", Face: %d", pCurrentError->m_paiErrors[5]);
if (numIndex >= 4) fprintf(GetLogFile(), ", Loop: %d", pCurrentError->m_paiErrors[6]);
if (numIndex >= 5) fprintf(GetLogFile(), ", CoEdge/Edge: %d", pCurrentError->m_paiErrors[7]);
fprintf(GetLogFile(), ".\n\n");
}
}
// specify output file
A3DExport sExport(acDstFileName); // see A3DSDKInternalConvert.hxx for import and export detailed parameters
iRet = sHoopsExchangeLoader.Export(sExport);
if (!iRet)
return iRet;
//
// ### TERMINATE HOOPS EXCHANGE
//
// Check memory allocations
return (int)ListLeaks();
}

View File

@@ -0,0 +1,165 @@
<?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>{7CD4F74A-2286-4744-BF8C-C8B55E76730B}</ProjectGuid>
<RootNamespace>BrepAdaptor</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>
<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>
<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="BrepAdaptor.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="BrepAdaptor.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>