196 lines
7.6 KiB
C++
196 lines
7.6 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.
|
|
*
|
|
***********************************************************************************************************************/
|
|
/**
|
|
\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 <hoops_license.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), HOOPS_LICENSE);
|
|
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();
|
|
}
|