DATAKIT SDK  V2026.2
StartAPI.cpp File Reference

Functions

void ActivateApiOptions (Dtk_API *inoutMyApi)
 
void ActivateFeatureDump (Dtk_bool inDumpFeature)
 
void EnableReaders ()
 
int LaunchAPISample (int argc, char **argv)
 
Dtk_ErrorStatus ProcessCADFile (const Dtk_string &inInputFile, const Dtk_string &inOutputFolder)
 
Dtk_ErrorStatus SetSchemaDirectory (Dtk_API *inoutMyApi)
 

Function Documentation

◆ ActivateApiOptions()

void ActivateApiOptions ( Dtk_API inoutMyApi)
4 {
5 }

◆ ActivateFeatureDump()

void ActivateFeatureDump ( Dtk_bool  inDumpFeature)
8 {
9  toDumpFeatures = inDumpFeature;
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
63 #ifdef USE_PSKERNEL
65 #else
67 #endif
78 }

◆ LaunchAPISample()

int LaunchAPISample ( int  argc,
char **  argv 
)
29 {
30  ////////// Project Options //////////
31 
32  // Activate/Deactivate 3D PDF file creation (geometry, PMI, assembly, materials, etc.)
33  // This option requires Datakit tessellation.
35 
36  // Activate/Deactivate dumping of DTK classes to XML file.
38 
39  // Activate/Deactivate dumping of features (only for CatiaV5, Proe, UG NX).
41 
42  ////////// End Project Options //////
43 
44  // Enable the readers you want to use.
45  EnableReaders();
46 
47  // Set working directory for Dtk_API.
48 #ifndef Linux
49  wchar_t temporaryWorkingDirectory[1024];
50  wchar_t *retwc;
51  retwc = _wgetcwd(temporaryWorkingDirectory, 1024);
52 #else
53  char temporaryWorkingDirectory[1024];
54  getcwd(temporaryWorkingDirectory, 1024);
55 #endif
56 
57  std::cout << "Starting DATAKIT API..." << std::endl;
58 
59  // Start DATAKIT API with the working directory.
60  Dtk_ErrorStatus errorStatus = dtkNoError;
61  Dtk_API *myApi = Dtk_API::StartAPI(temporaryWorkingDirectory, errorStatus);
62  if (myApi == NULL)
63  {
64  // Report error if API fails to start.
65  std::cout << "Can't start DATAKIT API (error code: " << errorStatus << ")" << std::endl;
66  return dtkErrorAPINotStarted;
67  }
68  else
69  {
70  // Report successful API start.
71  std::cout << "DATAKIT API started successfully." << std::endl << std::endl;
72  }
73 
74  // Activate additional API options.
75  ActivateApiOptions(myApi);
76 
77  // Initialize tessellation library if PDF export is enabled.
79  {
81  }
82 
83  // Set Schema directory (required for some readers).
84  SetSchemaDirectory(myApi);
85 
86  // Supported extensions: sat, prt, asm, igs, iges, jt, vda, CATDrawing, CATPart, CATProduct,
87  // cgr, model, x_t, x_b, xmt, par, sldprt, step, stp, ipt, iam, dwg, and more.
88  // Integration is identical for all supported file types.
89 
90  // Process each input file.
91  for (int i = 1; i < argc; i++)
92  {
93  Dtk_string inputFile = argv[i];
94 
95  // Start measuring processing time.
96  time_t startTime;
97  time(&startTime);
98 
99  // Process the current file.
100  Dtk_ErrorStatus curError = ProcessCADFile(inputFile, "");
101 
102  // Stop measuring processing time.
103  time_t stopTime;
104  time(&stopTime);
105 
106  if (curError)
107  {
108  // Report any errors encountered during processing.
109  std::cout << "Error processing file: " << inputFile.c_str()
110  << " (" << dtkTypeError(curError).c_str() << ")" << std::endl;
111  }
112  else
113  {
114  // Report successful processing time.
115  double elapsedTime = difftime(stopTime, startTime);
116  std::cout << "File: " << inputFile.c_str()
117  << " successfully processed in " << elapsedTime << " s" << std::endl << std::endl;
118  }
119  }
120 
121  // Close tessellation kernel if PDF export is enabled.
122  if (IsPdfDumpActivated() == DTK_TRUE)
123  {
124  EndTesselation();
125  }
126 
127  // Stop DATAKIT API at the end.
128  Dtk_API::StopAPI(myApi);
129 
130  std::cout << "Stopping DATAKIT API" << std::endl;
131 
132  return 0;
133 }

◆ ProcessCADFile()

Dtk_ErrorStatus ProcessCADFile ( const Dtk_string inInputFile,
const Dtk_string inOutputFolder 
)
19 {
20  // Clear the list of processed components before starting.
21  ProcessedComponents.clear();
22 
23  // Get the current Datakit API instance.
24  Dtk_API* myApi = Dtk_API::GetAPI();
25 
26  std::cout << "Processing file: " << inInputFile.c_str() << std::endl;
27 
28  // Retrieve and display the file version.
29  Dtk_string fileVersion;
30  Dtk_ErrorStatus stError = myApi->GetFileVersion(inInputFile, fileVersion);
31 
32  if( fileVersion.is_not_NULL() )
33  {
34  // Display the file version.
35  std::cout << "File version: " << fileVersion.c_str() << std::endl;
36  }
37 
38  if (stError != dtkNoError)
39  {
40  // Report error if unable to get file version.
41  std::cout << "Unable to get file version (error code: " << dtkTypeError(stError).c_str() << ")" << std::endl;
42  return stError;
43  }
44 
45  // Set log file for the reader (inventory, missing files in assembly, etc.).
46  Dtk_string logFilePath = inInputFile.filename() + Dtk_string("-dtk.log");
47  myApi->SetLogFile( logFilePath );
48 
49  // Initialize XML writing if XML export is enabled.
50  Dtk_ErrorStatus stErrorXml = dtkNoError;
51  if (IsXmlDumpActivated())
52  {
53  stErrorXml = XmlWriteInit(inInputFile, inOutputFolder);
54  }
55 
56  // Initialize PDF writing if PDF export is enabled.
57  Dtk_ErrorStatus stErrorPdf = dtkNoError;
58  if (IsPdfDumpActivated())
59  {
60  stErrorPdf = PdfInitWrite(inInputFile, inOutputFolder);
61  }
62 
63  // Open the input file and obtain the corresponding document.
64  Dtk_MainDocPtr tmpDoc;
65  Dtk_ErrorStatus err = myApi->OpenDocument(inInputFile, tmpDoc);
66 
67  // If successful, write the document (see WriteDocument.cpp)
68  if (err == dtkNoError && tmpDoc.IsNotNULL())
69  {
70  WriteDocument(tmpDoc);
71  }
72  else
73  {
74  // Report error if unable to open the document.
75  std::cout << "Error with OpenDocument (error code: " << err << " " << dtkTypeError(err).c_str() << ")" << std::endl;
76  }
77 
78  // Close the opened document.
79  err = myApi->EndDocument(tmpDoc);
80 
81  // Finalize XML writing if XML export is enabled.
82  if (IsXmlDumpActivated())
83  {
84  XmlWriteEnd();
85  }
86 
87  // Finalize PDF writing if PDF export is enabled.
88  if (IsPdfDumpActivated())
89  {
90  PdfEndWrite(inInputFile);
91  }
92 
93  return err;
94 }

◆ 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()
SetSchemaDirectory
Dtk_ErrorStatus SetSchemaDirectory(Dtk_API *inoutMyApi)
Definition: EnableReaders.cpp:82
NavisReader::Enable
static Dtk_bool Enable()
LavaReader::Enable
static Dtk_bool Enable()
CgmReader::Enable
static Dtk_bool Enable()
DwgDtkReader::Enable
static Dtk_bool Enable()
GltfReader::Enable
static Dtk_bool Enable()
StlReader::Enable
static Dtk_bool Enable()
Dtk_SmartPtr::IsNotNULL
Dtk_bool IsNotNULL() const
Definition: util_ptr_dtk.hpp:119
SwReader::Enable
static Dtk_bool Enable()
toDumpFeatures
Dtk_bool toDumpFeatures
Definition: WriteFeature.cpp:5
_3dmReader::Enable
static Dtk_bool Enable()
JtReader::Enable
static bool Enable()
ActivateApiOptions
void ActivateApiOptions(Dtk_API *inoutMyApi)
Definition: ActivateApiOptions.cpp:3
ActivatePdfDump
void ActivatePdfDump(Dtk_bool inDumpPDF)
Definition: PdfWrite.cpp:24
CerconReader::Enable
static Dtk_bool Enable()
DTK_TRUE
#define DTK_TRUE
Definition: define.h:719
Dtk_API::StartAPI
static Dtk_API * StartAPI(const Dtk_string &inTemporyDirectory, Dtk_ErrorStatus &outErrorCode, const Dtk_string &inCustomerID=Dtk_string())
Start DATAKIT API.
InitTesselation
DtkErrorStatus InitTesselation()
Definition: TesselationEngine.cpp:18
F3dReader::Enable
static Dtk_bool Enable()
Dtk_string
This is a high level string class.
Definition: dtk_string.hpp:53
WriteDocument
Dtk_ErrorStatus WriteDocument(Dtk_MainDocPtr inDocument)
Definition: WriteDocument.cpp:14
PlmXmlReader::Enable
static Dtk_bool Enable()
XmlWriteInit
Dtk_ErrorStatus XmlWriteInit(Dtk_string inInputFile, const Dtk_string &inOutputFolder)
Definition: XmlWrite.cpp:22
ActivateFeatureDump
void ActivateFeatureDump(Dtk_bool inDumpFeature)
Definition: WriteFeature.cpp:7
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)
DTK_FALSE
#define DTK_FALSE
Definition: define.h:720
RevitReader::Enable
static Dtk_bool Enable()
dtkErrorAPINotStarted
@ dtkErrorAPINotStarted
Definition: error_dtk.hpp:107
ProeReader::Enable
static Dtk_bool Enable()
CaddsReader::Enable
static Dtk_bool Enable()
InvReader::Enable
static Dtk_bool Enable()
ProCeraReader::Enable
static Dtk_bool Enable()
ActivateXmlDump
void ActivateXmlDump(Dtk_bool inDumpXml)
Definition: XmlWrite.cpp:12
Zw3dReader::Enable
static Dtk_bool Enable()
Dtk_string::is_not_NULL
Dtk_bool is_not_NULL() const
UgReader::Enable
static Dtk_bool Enable()
Dtk_API::GetAPI
static Dtk_API * GetAPI()
Get DATAKIT API.
Dtk_string::filename
Dtk_string filename() const
File Utility : Retrieves the filename in Dtk_string form.
CatiaV5Reader::Enable
static Dtk_bool Enable()
PdfEndWrite
void PdfEndWrite(const Dtk_string &inInputFile)
Definition: PdfWrite.cpp:83
IgesReader::Enable
static Dtk_bool Enable()
EndTesselation
void EndTesselation()
Definition: TesselationEngine.cpp:47
CatiaV6Reader::Enable
static Dtk_bool Enable()
XmlWriteEnd
Dtk_ErrorStatus XmlWriteEnd()
Definition: XmlWrite.cpp:39
IfcReader::Enable
static Dtk_bool Enable()
Dtk_ErrorStatus
Dtk_ErrorStatus
Definition: error_dtk.hpp:6
DcmReader::Enable
static Dtk_bool Enable()
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.
EnableReaders
void EnableReaders()
Definition: EnableReaders.cpp:12
CerecReader::Enable
static Dtk_bool Enable()
CreoviewReader::Enable
static Dtk_bool Enable()
ProcessedComponents
Dtk_tab< Dtk_ID > ProcessedComponents
Definition: WritePrototype.cpp:16
XmtReader::Enable
static Dtk_bool Enable()
FbxReader::Enable
static Dtk_bool Enable()
Dtk_API::StopAPI
static void StopAPI(Dtk_API *&inAPI, Dtk_bool inWriteTimeInLog=1)
Stop DATAKIT API.
IsXmlDumpActivated
Dtk_bool IsXmlDumpActivated()
Definition: XmlWrite.cpp:17
PdfInitWrite
Dtk_ErrorStatus PdfInitWrite(const Dtk_string &inInputFileName, const Dtk_string &inOutputFolder)
Definition: PdfWrite.cpp:34
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:149
VdaReader::Enable
static Dtk_bool Enable()
SolidEdgeReader::Enable
static Dtk_bool Enable()
QifReader::Enable
static Dtk_bool Enable()
Dtk_API::SetLogFile
Dtk_ErrorStatus SetLogFile(const Dtk_string &inLogFile)
Set Log File.
IsPdfDumpActivated
Dtk_bool IsPdfDumpActivated()
Definition: PdfWrite.cpp:29
Dtk_API
Definition: dtk_api.hpp:75
ProcessCADFile
Dtk_ErrorStatus ProcessCADFile(const Dtk_string &inInputFile, const Dtk_string &inOutputFolder)
Definition: OpenDocument.cpp:18
AcisReader::Enable
static Dtk_bool Enable()