DATAKIT SDK  V2026.4
StartAPIToParasolidWithSession.cpp File Reference

Functions

void ActivateApiOptions (Dtk_API *inoutMyApi)
 
void EnableReaders ()
 
int LaunchAPISampleToParasolidWithSession (int argc, char **argv)
 
Dtk_ErrorStatus ProcessCADFileToParasolidWithExistingSession (const Dtk_string &inInputFile, const Dtk_string &inOutputFolder)
 
Dtk_ErrorStatus SetSchemaDirectory (Dtk_API *inoutMyApi)
 

Function Documentation

◆ ActivateApiOptions()

void ActivateApiOptions ( Dtk_API *  inoutMyApi)
8 {
9  DTK_UNUSED( inoutMyApi );
10 }

◆ EnableReaders()

void EnableReaders ( )
13 {
14  // Supported formats and their extensions:
15  // Acis: .sat
16  // Catiav4: .model (2D/3D), .session, .dlv
17  // Catiav5: .CATDrawing, .CATPart, .CATProduct
18  // Cgr: .cgr
19  // Dwg: .dwg
20  // Iges: .igs, .iges
21  // Inventor: .ipt, .iam
22  // Jt: .jt
23  // Parasolid: .x_t, .x_b, .xmt
24  // Proe: .prt, .asm
25  // Solid Edge: .par, .asm
26  // Solidworks: .sldprt, .sldasm
27  // Step: .step, .stp
28  // UG NX: .prt (2D/3D)
29  // Vda: .vda
30  // ZW3D: .z3prt, .z3asm, .z3
31 
32  // Enable the readers you want to use.
35 #ifndef Linux
36 #ifndef ARM64
38 #endif
39 #endif
62 #ifdef USE_PSKERNEL
64 #else
66 #endif
78 }

◆ LaunchAPISampleToParasolidWithSession()

int LaunchAPISampleToParasolidWithSession ( int  argc,
char **  argv 
)
39 {
40  // Enable all available Datakit readers.
41  EnableReaders();
42 
43  // Retrieve the current working directory.
44 #ifndef Linux
45  wchar_t workingDirectory[ 1024 ];
46  wchar_t* retwc = _wgetcwd( workingDirectory, 1024 );
47  (void)retwc;
48 #else
49  char workingDirectory[ 1024 ];
50  getcwd( workingDirectory, 1024 );
51 #endif
52 
53  // Start the Datakit API.
54  Dtk_ErrorStatus errorStatus = dtkNoError;
55  cout << "Starting DATAKIT API" << endl;
56  Dtk_API* myAPI = Dtk_API::StartAPI( workingDirectory, errorStatus );
57  if( myAPI == NULL )
58  {
59  cout << "Cannot start DATAKIT API: " << errorStatus << endl;
60  return dtkErrorAPINotStarted;
61  }
62 
63  ActivateApiOptions( myAPI );
64 
65  // Preserve native kernel data so psw can write original kernel geometry.
66  myAPI->ActivateKeepKernelData();
67 
68  SetSchemaDirectory( myAPI );
69 
70  // Start a single PK session shared across all processed files.
72 
73  // Process each input file.
74  for( int i = 1; i < argc; ++i )
75  {
76  Dtk_string arg = argv[ i ];
77 
78  time_t startTime;
79  time( &startTime );
80 
81  // Convert to Parasolid via psw and receive bodies into the shared session.
82  Dtk_ErrorStatus curError =
84 
85  time_t stopTime;
86  time( &stopTime );
87 
88  if( curError != dtkNoError )
89  cout << "Error processing file " << arg.c_str()
90  << " (" << dtkTypeError( curError ).c_str() << ")" << endl;
91  else
92  {
93  double elapsedTime = difftime( stopTime, startTime );
94  cout << "File " << arg.c_str()
95  << " processed in " << elapsedTime << " s" << endl;
96  }
97  }
98 
99  // Enumerate all bodies accumulated in the shared PK session.
101 
102  // Stop the PK session, then stop the Datakit API.
104  cout << "--- Parasolid session closed ---" << endl;
105 
106  Dtk_API::StopAPI( myAPI );
107  cout << "Stopping DATAKIT API" << endl;
108 
109  return 0;
110 }

◆ ProcessCADFileToParasolidWithExistingSession()

Dtk_ErrorStatus ProcessCADFileToParasolidWithExistingSession ( const Dtk_string &  inInputFile,
const Dtk_string &  inOutputFolder 
)
30 {
31  // Activate the PK session mode directly via the header API.
32  // This removes the need for any command-line flag.
33  ActivatePsSession( true );
34  // Activate in-memory mode if desired (no .x_t file on disk).
35  ActivatePsMemory( true );
36 
37  Dtk_API* myAPI = Dtk_API::GetAPI();
38 
39  std::cout << "Processing file: " << inInputFile.c_str() << std::endl;
40 
41  // Optionally retrieve and display the source file version.
42  Dtk_string fileVersion;
43  Dtk_ErrorStatus stError = myAPI->GetFileVersion( inInputFile, fileVersion );
44  if( fileVersion.is_not_NULL() )
45  std::cout << "File version: " << fileVersion.c_str() << std::endl;
46  if( stError != dtkNoError )
47  {
48  std::cout << "Error retrieving file version: " << dtkTypeError( stError ).c_str() << std::endl;
49  return stError;
50  }
51 
52  // Optional: activate a log file to capture reader diagnostics.
53  myAPI->SetLogFile( "DtkLogFile.txt" );
54 
55  // Initialise the Parasolid writer:
56  // IsPsMemoryActivated() -> write to in-memory buffer (no file on disk)
57  // default -> write to a .x_t file
58  Dtk_ErrorStatus stErrorPsw;
59  if( IsPsMemoryActivated() )
60  stErrorPsw = PswWriteInitMemory();
61  else
62  stErrorPsw = PswWriteInit( inInputFile, inOutputFolder );
63 
64  // Open the source document.
65  Dtk_MainDocPtr tmpDoc;
66  Dtk_ErrorStatus err = myAPI->OpenDocument( inInputFile, tmpDoc );
67 
68  if( err == dtkNoError && tmpDoc.IsNotNULL() )
69  {
70  // Traverse the document and write Parasolid output.
71  if( stErrorPsw == dtkNoError )
72  PswWriteDocument( tmpDoc );
73  }
74  else
75  {
76  std::cout << "Error OpenDocument: " << dtkTypeError( err ).c_str() << std::endl;
77  }
78 
79  // Close the source document and release its resources.
80  myAPI->EndDocument( tmpDoc );
81 
82  // Finalise and close the psw output.
83  // After this call the psw-internal PK session is fully closed.
84  PswWriteEnd();
85 
86  // Receive the written bodies into the caller-owned PK session.
87  if( IsPsMemoryActivated() )
89  else
91 
92  return err;
93 }

◆ SetSchemaDirectory()

Dtk_ErrorStatus SetSchemaDirectory ( Dtk_API *  inoutMyApi)
83 {
84  Dtk_ErrorStatus schemaStatus;
85 
86  // Define the schema directory path.
87  Dtk_string schemaDirectory = "./Schema";
88 
89 #ifndef Linux
90  char tmpFullPathSchemaDir[_MAX_PATH];
91 
92  if (_fullpath(tmpFullPathSchemaDir, schemaDirectory.c_str(), _MAX_PATH) != NULL)
93  schemaStatus = inOutMyApi->SetSchemaDir(tmpFullPathSchemaDir);
94  else
95  schemaStatus = inOutMyApi->SetSchemaDir(schemaDirectory);
96 #else
97  schemaStatus = inOutMyApi->SetSchemaDir(schemaDirectory);
98 #endif
99 
100 #ifdef USE_PSKERNEL
101  if (schemaStatus != dtkNoError)
102  {
103  std::cout << "Schema directory error (required for readers based on PsKernel or CADDS): "
104  << dtkTypeError(schemaStatus).c_str() << std::endl;
105  }
106 #endif
107 
108  return schemaStatus;
109 }
ObjReader::Enable
static Dtk_bool Enable()
Dtk_API::EndDocument
Dtk_ErrorStatus EndDocument(Dtk_MainDocPtr &inoutDocument)
Close a Document.
CgrReader::Enable
static Dtk_bool Enable()
SmgReader::Enable
static Dtk_bool Enable()
NavisReader::Enable
static Dtk_bool Enable()
LavaReader::Enable
static Dtk_bool Enable()
DwgDtkReader::Enable
static Dtk_bool Enable()
GltfReader::Enable
static Dtk_bool Enable()
StlReader::Enable
static Dtk_bool Enable()
IsPsMemoryActivated
bool IsPsMemoryActivated()
Definition: LoadBodiesIntoSession.cpp:48
Dtk_SmartPtr::IsNotNULL
Dtk_bool IsNotNULL() const
Definition: util_ptr_dtk.hpp:119
SwReader::Enable
static Dtk_bool Enable()
_3dmReader::Enable
static Dtk_bool Enable()
JtReader::Enable
static bool Enable()
CerconReader::Enable
static Dtk_bool Enable()
Dtk_API::StartAPI
static Dtk_API * StartAPI(const Dtk_string &inTemporyDirectory, Dtk_ErrorStatus &outErrorCode, const Dtk_string &inCustomerID=Dtk_string())
Start DATAKIT API.
F3dReader::Enable
static Dtk_bool Enable()
Dtk_string
This is a high level string class.
Definition: dtk_string.hpp:53
PlmXmlReader::Enable
static Dtk_bool Enable()
EnableReaders
void EnableReaders()
Definition: LibReadersSample/RunThroughAPI/GetStarted/EnableReaders.cpp:12
CatiaV4Reader::Enable
static Dtk_bool Enable()
StepReader::Enable
static Dtk_bool Enable()
Dtk_API::OpenDocument
Dtk_ErrorStatus OpenDocument(const Dtk_string &inInputFile, Dtk_MainDocPtr &outDocument)
Open a Document (call EndDocument to close it)
PswGetLastOutputFile
Dtk_string PswGetLastOutputFile()
Definition: WriteParasolid.cpp:25
StartSharedPsSession
void StartSharedPsSession()
Definition: LoadBodiesIntoSession.cpp:140
RevitReader::Enable
static Dtk_bool Enable()
dtkErrorAPINotStarted
@ dtkErrorAPINotStarted
Definition: error_dtk.hpp:109
ProeReader::Enable
static Dtk_bool Enable()
CaddsReader::Enable
static Dtk_bool Enable()
ReceiveBodiesIntoCurrentPsSessionFromStream
void ReceiveBodiesIntoCurrentPsSessionFromStream(const Dtk_tab< char > &inStream)
Definition: LoadBodiesIntoSession.cpp:319
InvReader::Enable
static Dtk_bool Enable()
PswWriteEnd
Dtk_ErrorStatus PswWriteEnd()
Definition: WriteParasolid.cpp:442
EnumerateBodiesInSession
void EnumerateBodiesInSession()
Definition: LoadBodiesIntoSession.cpp:147
ProCeraReader::Enable
static Dtk_bool Enable()
Zw3dReader::Enable
static Dtk_bool Enable()
Dtk_string::is_not_NULL
Dtk_bool is_not_NULL() const
PswGetLastStream
const Dtk_tab< char > & PswGetLastStream()
Definition: WriteParasolid.cpp:32
UgReader::Enable
static Dtk_bool Enable()
Dtk_API::GetAPI
static Dtk_API * GetAPI()
Get DATAKIT API.
PswWriteInitMemory
Dtk_ErrorStatus PswWriteInitMemory()
Definition: WriteParasolid.cpp:419
CatiaV5Reader::Enable
static Dtk_bool Enable()
IgesReader::Enable
static Dtk_bool Enable()
CatiaV6Reader::Enable
static Dtk_bool Enable()
ReceiveBodiesIntoCurrentPsSession
void ReceiveBodiesIntoCurrentPsSession(const Dtk_string &inXtFile)
Definition: LoadBodiesIntoSession.cpp:290
IfcReader::Enable
static Dtk_bool Enable()
Dtk_ErrorStatus
Dtk_ErrorStatus
Definition: error_dtk.hpp:6
DcmReader::Enable
static Dtk_bool Enable()
SetSchemaDirectory
Dtk_ErrorStatus SetSchemaDirectory(Dtk_API *inoutMyApi)
Definition: LibReadersSample/RunThroughAPI/GetStarted/EnableReaders.cpp:82
PsReader::Enable
static Dtk_bool Enable()
Dtk_SmartPtr
Definition: util_ptr_dtk.hpp:37
dtkTypeError
Dtk_string dtkTypeError(Dtk_Int32 errNumero)
Dtk_string::c_str
const char * c_str() const
Retrieve the ASCII conversion string.
StopSharedPsSession
void StopSharedPsSession()
Definition: LoadBodiesIntoSession.cpp:141
CerecReader::Enable
static Dtk_bool Enable()
CreoviewReader::Enable
static Dtk_bool Enable()
UsdReader::Enable
static Dtk_bool Enable()
PswWriteDocument
void PswWriteDocument(Dtk_MainDocPtr inDocument)
Definition: WriteParasolid.cpp:349
XmtReader::Enable
static Dtk_bool Enable()
Dtk_API::ActivateKeepKernelData
void ActivateKeepKernelData()
Keep Kernel Data option (see "How to use KeepKernelData option")
FbxReader::Enable
static Dtk_bool Enable()
Dtk_API::StopAPI
static void StopAPI(Dtk_API *&inAPI, Dtk_bool inWriteTimeInLog=1)
Stop DATAKIT API.
ProcessCADFileToParasolidWithExistingSession
Dtk_ErrorStatus ProcessCADFileToParasolidWithExistingSession(const Dtk_string &inInputFile, const Dtk_string &inOutputFolder)
Definition: OpenDocumentToParasolidWithExistingSession.cpp:27
ActivateApiOptions
void ActivateApiOptions(Dtk_API *inoutMyApi)
Definition: ActivateApiOptions.cpp:7
ActivatePsSession
void ActivatePsSession(bool inActivate)
Definition: LoadBodiesIntoSession.cpp:43
PswWriteInit
Dtk_ErrorStatus PswWriteInit(const Dtk_string &inInputFile, const Dtk_string &inOutputFolder)
Definition: WriteParasolid.cpp:388
Dtk_API::GetFileVersion
Dtk_ErrorStatus GetFileVersion(const Dtk_string &inInputFile, Dtk_string &outVersion)
Independant method to get version of inInputFile.
dtkNoError
@ dtkNoError
Definition: error_dtk.hpp:151
VdaReader::Enable
static Dtk_bool Enable()
SolidEdgeReader::Enable
static Dtk_bool Enable()
ActivatePsMemory
void ActivatePsMemory(bool inActivate)
Definition: LoadBodiesIntoSession.cpp:44
QifReader::Enable
static Dtk_bool Enable()
DTK_UNUSED
#define DTK_UNUSED(a)
Definition: define.h:729
Dtk_API::SetLogFile
Dtk_ErrorStatus SetLogFile(const Dtk_string &inLogFile)
Set Log File.
Dtk_API
Definition: dtk_api.hpp:75
AcisReader::Enable
static Dtk_bool Enable()